mardi 4 août 2015

How do I check if the number of lines in a set of files is not equal to a certain number? (Bash)

I want to detect which one of my files is corrupt, and by corrupt it means that the file does not have 102 lines in it. I want the for loop that I'm writing to output a error message giving me the file name of the corrupt files. I have files named ethane1.log ethane2.log ethane3.log ... ethane10201.log .

for j in {1..10201} do if [ ! (grep 'C 2- C 5' ethane$j.log | cut -c 22- | tail -n +2 | awk '{for (i=1;i<=NF;i++) print $i}'; done | wc -l) == 102] then echo "Ethane$j.log is corrupt." fi done

When the file is not corrupt, the input:

grep 'C 2- C 5' ethane$j.log | cut -c 22- | tail -n +2 | awk '{for (i=1;i<=NF;i++) print $i}'; done | wc -l

returns:

102

Or else it is another number.

Only thing is, I'm not sure the syntax for the if construct (How to create a variable from the 102 output of wc -l, and then how to check if it is equal to or not equal to 102.)

A sample output would be:

Ethane100.log is corrupt.
Ethane2010.log is corrupt.
Ethane10201.log is corrupt.

Aucun commentaire:

Enregistrer un commentaire