Comparing Data file with Crtl file

Print Friendly

By Prashanth B

Hi,
I need to compare a file with its contents matching to that of another file(filename , received date and record count).
Lets say has File A original data

Code:

Ex -
1,abc,1234
2,bcd,4567
3,cde,8901


and File B has details of File A

Code:

Ex-
FILEA.TXT|06/17|2010|3
(filename)|(received date)|(record count)


I need to fetch the details(filename , received date and record count) File A ,and must be compared with File B and it should match.I wrote a code which covers all the requirements but it throws me an error. It throws error at line 62 stating ‘]’ missing and line 72 : argument expected. Kindly have a look at my script and let me know where I went wrong.

Original Script

Code:

echo "Initialising the run time parameter for FOLDER path..."
cd $path #path will be given here
echo "n Folder path of the unzipped files and CNTRL file: $1 "
echo "n n Reading the content from CNTRL file and asssigning the values to variables..."
while IFS='|' && read fname Process_dt rec_cnt
do
echo "n $fname $Process_dt $rec_cnt "
echo "n Checking if the File exist in the folder..."
if [ -f $fname ] ; then
echo "n $fname Exist"
echo "n n Reading linecount for the corresponding file and storing it in a variable..."

cat $fname | wc -l | read linecount
echo "n Reading Processdate for the corresponding file and storing it in a variable..."
ls -l | awk '{print $6 $7 S8}'| nawk ' { months=" JanFebMarAprMayJunJulAugSepOctNovDec";date=$2;month=index(months,substr($1,1,3))/3; year=$3; printf("%02s/%02s/%s
n",month,date,year)}'|read Proc_dt;
echo "n checking if record count and Process date of the file matches with the CNTRL file entry..."
if [ ($linecount -eq $rec_cnt) && ($Proc_dt -eq $Process_dt) ] ; then
echo "n n Record Count and Process date matches from both files"
return 0
else
if [ ($linecount -ne $rec_cnt)]
echo "n n Record Count doesnot match"
return 1
fi
else
echo "n n Process date doesnot match"
return 1
fi
fi
echo "Passing the run time parameter for CNTRL file name..."
done < POR.CRTl
echo " Filename,Record count and Process date validated against file $2"


I will be incorporating this into a cmd task where I will pass path and CRTL file name as variable.

From: http://www.unix.com/shell-programming-scripting/221355-comparing-data-file-crtl-file.html

FavoriteLoadingAdd to favorites

Leave a Reply

Your email address will not be published. Required fields are marked *