2

There is an input file that has TAB delimited columns.

We need to remove the lines which has "NA" for the fourth AND the eleventh column.

Question: how can we do this in awk?

1
  • 1
    Please always include an example of your input and your desired output, it makes understanding your question much easier and greatly increases your chances of getting a useful answer. Do you want to remove lines that have NA on both the 4th and the 11th field or on either?
    – terdon
    Oct 21, 2014 at 18:53

2 Answers 2

3
awk -F"\t" '$4 != "NA" || $11 != "NA"' filename

Note, awk does not edit the file in-place. If you want to save the changes back to the file, then:

tmp=$(mktemp)
awk -F"\t" '...' filename > "$tmp" && mv "$tmp" filename
3

You tell awk to print the lines that do not meet your criteria.

BEGIN { FS="\t" }
$4 != "NA" || $11 != "NA"

This is a reverse of boolean logic where ~a|~b == a&b.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .