Why sum of recs in awk don't match total rec count?

I'm using awk to determine if a field starting in position 604 for length of 10 is not equal to ALL spaces. It's searching several files which are in the current directory.

The below awk indicates that there are 84 records on all files where this field IS NOT equal to ALL spaces ( there are 10 spaces between the quotes).

 
awk 'substr($0,604,10)!="          " {print substr($0,604,10)}' LPM_BENE_BATCH_*.txt | wc -l
84

I then want to run the negate of the above to validate against the total record count of all files.
The below awk indicates that there are 444 records on all files where this field equals all spaces.

 
awk 'substr($0,604,10)=="          " {print substr($0,604,10)}' LPM_BENE_BATCH_*.txt | wc -l
444

But when I count all records on all the same files the above 2 awk commands are searching I get 1 less record then when I sum the above counts (84+444 = 528).

 
wc -l LPM_BENE_BATCH_*.txt 
527 total 

What are some factors that could cause my total to not match?

wc counts the number of newlines. If one of the files doesn't end in a newline, that would explain the discrepancy, since awk would add the missing newline when it prints that record.

Regards,
Alister

1 Like

Thanks for the explanation alister! I was able to find the offending line missing the newline char.