I have several (427 to be precise) text files with a million lines each containing 31 numbers separated be spaces (possible double spaces). However there might be some data corruption and there may be lines containing junk.
I now want to check if every line satisfies the property of containing 31 items separated by spaces (I assume that those items are numbers. A method which checks that too would be better).
My current way is
while read line; do if [ $(echo "$line" | sed 's/ /\n/g' | grep -v "^$" | wc -l) -ne 31 ] then echo "$file bad"; fi done < $file
This replaces all spaces of a line by newlines, filters empty lines, counts the number of lines and compares it to 31.
This approach is slow and there's probably a much better way involving some fancy regular expression. What would be a faster way?