Tag Archives: DAT

Case script to get missing sequence among files

By arm

I want to use case statement to find the range of missing sequence in my directory which it has some few ( dat & DAT ) files

my directory /home/arm/my_folder/20130428 contains :

f01_201304280000.DAT
f01_201304280001.DAT
f01_201304280003.DAT
f02_201304280000.dat
f02_201304280002.dat
f02_201304280003.dat

Code:

!#/bin/sh
main="/home/arm/my_folder"

for file in $( find $main -type f | awk -F "/" '{ print $NF}' | cut -c1-3 )
do

case $file in
f01) start=$( find $main -type f -name "$file*" | sort | cut -c13-16 | head -1)
end=$( find $main -type f -name "$file*" | sort | cut -c13-16 | tail -1 )
diff=$(( $end - $start ))
miss=$file*diff*
echo $miss

f02) start=$( find $main -type f -name "$file*" | sort | cut -c13-16 | head -1)
end=$( find $main -type f -name "$file*" | sort | cut -c13-16 | tail -1 )
diff=$(( $end - $start ))
miss=$file*diff*
echo $miss
esac

done


hope you can correct me if I were wrong ?

Source: FULL ARTICLE at The UNIX and Linux Forums

FTP Status check(whether it is suuccessful or not)

By Kannannair

Hi Friends

I need to check the status of FTP connection i.e. Whether it is successful or not

I have tried this by assigning the FTP connection script to a variable and after that using this variable I tried to check the status.

In the below code snippet I am trying to assign the FTP conenction status to a variable.

Code:


STATUS=`ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
prompt off
cd /user/sba-appl/test/sscr/ramu/
lcd /user/sba-appl/productie/sscr/darshan
mget get.DAT
bye
EOF`


Can anyone tell whether this approach is correct or not. When i am trying this method FTP connection is not happening. Whether we can assign the FTP connection like this

Because after this i can use the above variable and check the status for various FTP states like 226 553etc using the grep command.

Thanks and Regards
Darshan

From: http://www.unix.com/shell-programming-scripting/221797-ftp-status-check-whether-suuccessful-not.html

FTP Status check(whether it is successful or not)

By Kannannair

Hi Friends

I need to check the status of FTP connection i.e. Whether it is successful or not

I have tried this by assigning the FTP connection script to a variable and after that using this variable I tried to check the status.

In the below code snippet I am trying to assign the FTP conenction status to a variable.

Code:


STATUS=`ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
prompt off
cd /user/sba-appl/test/sscr/ramu/
lcd /user/sba-appl/productie/sscr/darshan
mget get.DAT
bye
EOF`


Can anyone tell whether this approach is correct or not. When i am trying this method FTP connection is not happening. Whether we can assign the FTP connection like this

Because after this i can use the above variable and check the status for various FTP states like 226 553etc using the grep command.

Thanks and Regards
Darshan

From: http://www.unix.com/shell-programming-scripting/221797-ftp-status-check-whether-successful-not.html

Variable value substituion issue with awk command issue

By G.K.K

Hi All,

I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command.

The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The script is written with awk command as shown below but the DAT variable value is not substituting in the awk command. Please help me how to fix this issue. Expected output provided below.

sample.ksh
========

Code:

#!bin/ksh
DAT="0301"
NM="xyzxyz.4560301"
echo $NM | awk '/$DAT$/ { print $1 }'


expected output:
=============

Code:

xyzxyz.4560301


Thanks in Advance
G.K.K

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

awk with variable from sqlplus

By jonathanb30

Hi, I’m a it stuck on the below code where a variable is pulled from sqlplus and used in awk. It runs with no errors but still pulls back all records in the input file.

It should pull the max reference from sql plus and then only print those records where the reference value in column 1 is greater than the max reference value from the db.

Input file is a comma delimited and reference is a 14 digit number.

Thanks for any help in pointing me in the right direction!


value=`sqlplus -s user/pass << EOF
set heading off;
select max(reference) from cred_table;
exit;
EOF`

awk -F "," -v ref=$value'{if ($1 >= ref) printf("%-16s%-20s%-50s%-20s%-60s%-12s%-9s%-20s%-20s%-20s%-30s%-20s%-20s%-20s%-20s%-50s%-20s%-50s%-20s%-20s%-100s%-4s%-4s%-20s%-20s%-10s%-10s%-10s%-25s%-25s%-100s%-40s%-20s%-20s%-40s%-20s%-20s%-25s%-3s%-10s%-10s%-20s%-10s%-1s%-10s%-4s%-4s%-4s%-4s%-3s%-4s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10sn",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61)}' appfile_$Day.out > C_LIQ_CR_APP_RT_$Day.DAT


…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Pipe output missing date?

By DustinT

I’d like to have the output from this script piped to a text file that has the date at the beginning of it. For example, my ideal would be something like this

$./run_script.sh
$ls *.out
2013-Feb-26-output_filename.out

Here’s the code I’m using.


#! /bin/ksh

DAT=`date '+%Y-%b-%d'`

for d in /dir1 /dir2 /dir3

do
df -h $d|tail -1

done|>> $DAT_disk_usage.out


Instead of the output I’m expecting I get nothing… what am I missing?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

awk to append data to a file

By lost.identity

Hi

I search for certain values in a file across many directories using the following awk code


awk '/Sl.*thickness/ {Sl=$3;Tt=$NF}END{print Sl, Tt}' DILAT.DAT


What I would like to do is write out Sl and Tt obtained from these files from many directories to a single file. So for example if I’m doing this for 10 directories I would have 10 entries in the file where I write these values to.

Thanks!

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Read in numbers from a datafile

By lost.identity

Hi,

I want to be able to read numbers from many files which have the same general form as follows:

Code:

C3H8 4.032258004031807E-002
Phi = 1.000000E+00 Tau = 5.749E+00
sL0 = 3.805542E+01 dL0 = 1.514926E-02
Tb = 2.328291E+03 Tu = 3.450E+02 Alpha = 8.743165E-02
Mixture Visco. = 1.977164E-04 g/cm-s


What I would like to do is read the values of sL0, dL0, Tb, Tu and then write them out in another file as column data. For example,

Code:

sL0 dL0 Tb Tu
3.805542E+01 1.514926E-02 2.328291E+03 3.450E+02


what I have so far is

Code:

awk '/Sl/{Sl=$3}/Tb/{Tb=$3}END{print Sl, Tb}' DILAT.DAT


I don’t know how to pick Tu and dL0, as these variables are not at the start of the line.

Thanks!

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Cat writing only one record in the output file

By sagar.cumar

Hi All,

I have an input file containing data as below:

Input.DAT

Code:

XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|YY|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|AA|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111


I am executing below series of commands by validating 5th character of the input file (i.e. B in the said example).

Code:

rcnt=$(awk '{n++} END {print n}' Input.DAT)
fcnt=$(printf "%010d" $rowcount)
fnam1="OUTPUT"
fnam2="_B"
fnam3=".DAT"
nfnam=$(echo $fnam1$fnam2$fnam3)
touch $nfnam
echo "HEADER|$nfnam" > $nfnam
cat Input.DAT >> $nfnam
echo "TRAILER|$fcnt" >> $newfilename


The ouput file OUTPUT_B.DAT should contain as below:

Code:

HEADER|OUTPUT_B.DAT
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|YY|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|AA|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111
TRAILER|0000000002


But, I am getting only one detailed record in the ouput file.

Can anyone please advise.
Thanks a lot in advance.
Sagar.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Renaming CERTAIN files

By S. BASU

Hello

I have a folder with around a 100 files. Some of these files have an extension of .DAT.csv and the others are simply .DAT
I need to rename all those files ending in .DAT.csv to .DAT. I tried out the following script:


cd /data/AED/DEV/IN/MENSUEL/B3C/FEERIE/BASCULE/TEST
cnt=1
for fname in *.DAT.csv
do
mv $fname $fname.DAT
cnt=$(( $cnt + 1 ))
done


However and understandably so the files are renamed to .DAT.csv.DAT. I actually just need to get rid of the extensions and replace them with .DAT

Help appreciated…

Thanks & regards

S. BASU

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

awk command on .DAT file not working?

By sagar.cumar

Hi All,

I am trying to run awk command on .DAT file and it is not working. The same command is working on .txt file:
Contents of the file ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT:

HEADER|ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|A|YY|111111111|111111111|111111111||111111111|15|3|NNNNNN|Y|| 1|AAA|ZZZ|Y|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|A|AA|111111111|111111111|111111111||111111111|30|3|NNNNNN|Y|| 1|AAA|ZZZ|Y|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|YY|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3| AAA|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|AA|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3| AAA|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|C|YY|111111111|111111111|111111111|111111111|15|1|NNNNNN|N|4| AAA|BBB|N|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|C|AA|111111111|111111111|111111111|111111111|15|1|NNNNNN|N|4| AAA|BBB|N|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|D|YY|111111111|111111111|111111111|111111111|45|NNNNNN|Y|IND| 111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|D|AA|111111111|111111111|111111111|111111111|45|NNNNNN|Y|IND| 111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|E|YY|111111111|111111111|111111111||111111111|3|N|N|Y|1111111 11
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|E|AA|111111111|111111111|111111111||111111111|3|N|N|Y|1111111 11
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|F|YY|111111111|111111111|111111111|111111111|3|N|Y|111111111
XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|F|AA|111111111|111111111|111111111|111111111|3|N|Y|111111111
TRAILER|0000000012

Command I am using is below:
awk -F’|’ -v FN=DAT_FILENAME ‘/^[0-9]/{o=FN “_” $5 “.DAT“;print $0 >>o}’ ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT

Could any one please advise.

Thanks a lot in advance.

Sagar.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums