Delete all lines for which the kth field is 'NA'

awk, bash, lines

Solution

awk '$2 != "NA"' FS='|'

Input:

111|222|333
444|NA|666
777|888|999

Output:

111|222|333
777|888|999

Problem

Fix k, say k = 2 for illustration. Suppose we have a text file, `file.txt`, that has at least k columns, and the columns are delimited by the `|` symbol. How can I clean `file.txt` by deleting every row with the 2nd column equal to 'NA'? Lets say the output is directed to `outfile.txt`.

Original source