What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another script that does a validation check to make sure the wc -l for the detail is the same as the count in the header.
Questions: Is the exising code the best approach? If they match I need to continue on and execute another script.
Note: I took the exiting logic from other scripts so want to see what other options I have and if this is a clean approach.
First- I would like to parse the HDR file an grab the count of '78'.
Second- I would like to count the records/lines of the DET file.
Third- If the counts match then echo counts from both files and move on to execute script ABC.ksh.
Fourth- If the counts don't match exit with failure code 3.
I think you did not notice what I highlighted with red color, variable you defined using wc -l and cat doesn't return just an integer, it returns filename as well, in case of cat you will not get line count instead variable contains content of file you inputed . Please do check.
---------- Post updated at 12:54 AM ---------- Previous update was at 12:44 AM ----------
Updated code: Let me know if that is better or if I'm getting closer.
HDR File:
A: Cat /apps/fmp/ftp/Incoming/FPRS/FPRS/TEST.QDIA_TRIG_HDR* <pipe> to
B: awk '{print $2}' <pipe> integer to
C: sed 's/^0*//' which remove leading 0's.
DET File: Where I made an update.
A: cat /apps/fmp/ftp/Incoming/FPRS/FPRS/TEST.QDIA_TRIG_DET* <pipe> to
B: wc -l
HDR_count=$(cat /apps/fmp/ftp/Incoming/FPRS/FPRS/TEST.QDIA_TRIG_HDR* | awk '{print $2}' | sed 's/^0*//' )
DET_count=$(cat /apps/fmp/ftp/Incoming/FPRS/FPRS/TEST.QDIA_TRIG_DET* | wc -l )
if [ ${HDR_count} -ne ${DET_count} ]
then
echo
echo "HDR count[ ${HDR_count} ] net equal to DET count [ ${DET_count} ]"
exit 3
fi