Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove lines where the 10th column contains empty fields in text file in bash

I have a huge tab-delimited text file with 10 columns. Now I want to delete all rows from the file that contain no value in column 10.

For example:

a b c d e f g h i j
4 6 8 9 4 2 1 6 4 2
1 5 9 8 5 1 8 3 6 
1 6 8 5 4 7 7 9 4 7
4 5 8 9 9 2 1 8 4 
3 4 7 5 8 8 2 5 3 6

Expected output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a b c d e f g h i j
4 6 8 9 4 2 1 6 4 2
1 6 8 5 4 7 7 9 4 7
3 4 7 5 8 8 2 5 3 6

I would like to use something like:

awk '$10 == ""' print $0 file

>Solution :

Your command was almost there. You can try this:

awk '$10 != "" {print}' file
  • $10 != "" This tests if the 10th field is not empty
  • print prints the entire line
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading