0

I would like delete (exclude from output) some lines that have less than 23 columns in a file. For example:

BR1009298 338 1685 5839 1986 21111995 1 1 1 0 20032001 954 31266 1 1 4 5 205 95 27 3 2 BR1009298
BR1009304 339 5835 5797 1986 23011996 0 1 1 0 5081997 961 11189 3 1 3 4 1007 96 28 3 3 BR1009304
BR1009306 340 1578 0 1986 4041997 0 1 1 0 15081997 972 11189 9 1 9 9 501 97 42 3 0 
BR1009309 112180 5910 5791 1986 9011996 1 1 1 0 22111999 961 5445 5 1 1 1 1007 96 28 3 4 BR1009309

I would like delete the 3rd line, because it only has 22 columns. It is a big file and all lines that don't have 23 columns need be removed.

How can I do this?

4

Try this :

awk 'NF >= 23' file
  • 1
    The right tool for the job. – Wildcard Oct 21 '16 at 1:04
1

perl -ane 'if ($#F >= 22) { print }' < t where t contains your input data.

Note it's 22 because array's index start at 0 in perl.

0

And with good 'ol grep:

grep -E '(\s+\S+){22}' file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.