I have a text file with the following format:5 3 12 3 4..........i.e. space separated 3 columns of numbers/ However, some of the rows may be like:23 1So, I want to detect if the text file has any such inconsistencies and to print them out. How do I do this?
Count the number of rows in each column of a text file
text processing;sed;awk
Stephane Chazelas suggestedawk 'NF != 3'This is a simple way of printing all the lines that don't have exactly three columns. If you also want the command to return a failure status if any such line is found:awk 'NF != 3 {print; ++bad} END {exit(!!bad)}'Remove print; to not print anything and only report the presence of such lines through the exit status.You can also do this with grep:grep -Ev '^[^ ]+ +[^ ]+ +[^ ]+$'If you want to be more strict and print all the lines that don't consist of exactly three columns each containing an integer:grep -Ev '^([0-9]+) +([0-9]+) +([0-9]+)$'Use [ ]+ instead of + where  is a tab character if you want to allow one or more tab as column separators. Use (| +) to allow either exactly one tab or a sequence of spaces.