Count no of records if no. of fields are not equal to a certain variable
Specific to your file
Assuming
VarNumber
is a valid integer (not part of the request to secure this)- File(s) exists and are readeable
The commented code
awk -F '[|]' -v NotEqualTo="${VarNumber}" ' # if record have number of field NOT equal to given number NF != NotEqualTo { # Count the line c++ } # at end of file END { # print the count (only) print c } ' YourFile
Note:
- using
-F '[|]'
to avoid any missunderstanding with the RegEx OR depending option/config used VarNumber
is the batch variable with your number of field that are excluded
Generic for lot of file
awk -F '[|]' -v NotEqualTo="${VarNumber}" ' # Count if NF is NOT the number given and put info in array # 1 entry by file name NF != NotEqualTo {c[FILENAME]++} # at end of file, print the count (only) for each file (eement of array) END { for( f in c) print f " : " c[f] } ' YourFiles*