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
    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 '14 at 18:53
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:

awk -F"\t" '...' filename > "$tmp" && mv "$tmp" filename

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.

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.