I'd like to remove rows from a tab deliminated text file if a certain string is present in a specified column.

Example, If column 20 equals 5T, remove all rows from file and print remainder.

I'd also like to be able to do this for multiple values in column 20

Remove rows if column 20 equals 5T, 6T, and 7T.

  • By "remove rows", do you mean "output the rows until then and then stop"? – Kusalananda Sep 7 '17 at 12:42
  • 1
    Can provide examples of output and input files? – mrc02_kr Sep 7 '17 at 12:44

awk solution, according to your description:

awk -F'\t' '$20!~/^[567]T$/' file 
| improve this answer | |
  • Thanks but unfortunately this doesn't work. – Meghan Sep 7 '17 at 12:56
  • @Meghan, doesn't work - is not a description of the problem. There must be some errors or other issues that you need to describe – RomanPerekhrest Sep 7 '17 at 12:57
  • Sorry my response was sent to quickly. I was able to make it work with the following: awk -F'\t' '$20!="5T"&& $20!="4T"&& $20!="7T"' input.txt> output.txt – Meghan Sep 7 '17 at 13:14
  • @Meghan, this $20!="4T" is controversial with initial condition 20 equals 5T, 6T, and 7T., how do you feel? – RomanPerekhrest Sep 7 '17 at 13:20

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.