Compare file1 header count with file2 line count

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.

File1(Header File) Content:
FTB2013-10-10FTB_TRIG_DET_FILE_FPRS201310101239.TXT 000000004

File 2 (Detail File): wc -l should equal 4 in this case.

HDR_count=$(cat /apps/fmp/ftp/Incoming/FPRS/DC/FTB_TRIG_HDR* | awk '{print $2}'  | sed 's/^0*//' )
DET_count=$(wc -l /apps/fmp/ftp/Incoming/FPRS/DC/FTB_TRIG_DET* )
if [ ${HDR_count} -ne ${DET_count} ]
then
    echo
        echo "HDR count[ ${HDR_count} ] net equal to DET count [ ${DET_count} ]"
        exit 3
fi

---------- Post updated at 12:39 PM ---------- Previous update was at 08:50 AM ----------

Hello All,

If other examples of this are already documented please let me know and I will take a look. Thanks again.

From your script what I could see is you always receive exit code 3, provide sample input and expected output with clear description about the task.

Expectation:

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.

$ cat TEST.QDIA_TRIG_HDR_FILE201402250347.txt
PPADC2014-02-25PPADC_TRIG_DET_FILE201402250345.txt  000000078
$ wc -l TEST.QDIA_TRIG_DET_FILE201402250347.txt
78 TEST.QDIA_TRIG_DET_FILE201402250347.txt

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