I have tried like this, but could not able to figure out to solve the issue
#!/bin/ksh
set A=`cut -d "|" -f2 /home/user/FILE1.dat`
set E=`$A | awk "{sum +=$1} END { printf "%.2f", sum }"`
set B=`awk "END {print NR-1}" /home/user/FILE1.dat`
set C=`grep "NO OF RECORDS" /home/user/FILE.ctl | cut -d "|" -f2`
set D=`grep "CHECKSUM" /home/user/FILE.ctl | cut -d "|" -f2`
if ($E=$D and $B=$C) then
echo Status: Success
exit 0;
else
echo Status: Failed
exit 1;
fi
The first thing is to know how to count the records: At first look your file1.dat has 4 records, but in the controlfile it counts 3... is it to say it ignores the first record (being a heard?...)
I had a bit of time to look in depth, so forget the previous post and look:
#the script:
n12:/home/vbe/wks/z/test01 $ vi test01
#!/bin/ksh
cut -d "|" -f2 FILE1.dat|grep -v co> A # Your following awk needs an infile at the end so
#created A file to be removed at the end of execution
E=$( awk '{ sum +=$1 } END { printf "%.2f", sum }' A) #see now? and as mentionned in previous post single quote
echo E $E
B=$(awk "END {print NR-1}" FILE1.dat ) # The rest was correct - just changed to more modern ksh
echo B $B # syntax $( commands...)
C=$(grep "NO OF RECORDS" FILE.ctl | cut -d "|" -f2)
echo C $C
D=$(grep "CHECKSUM" FILE.ctl | cut -d "|" -f2)
echo D $D
rm A
if [ $E -eq $D -a $B -eq $C ] # You are testing numeric values no?
then
echo Status: Success
exit 0
else
echo Status: Failed
exit 1
fi
#exit...
:q
# Execution output:
n12:/home/vbe/wks/z/test01 $ ./test01
E 75.99
B 3
C 3
D 75.99
Status: Success
n12:/home/vbe/wks/z/test01 $