Using awk to remove lines from file that match text

I am trying to remove each line in which $2 is FP or RFP . I believe the below will remove one instance but not both. Thank you :).

file

12
123    FP
11
10    RFP

awk

awk -F'\t' '
$2 != "FP"' file

desired output

12
11

Hello cmccabe,

Could you please try following and let me know if this helps you.

awk '($2 !="FP" && $2 !="RFP")'  Input_file
OR
awk '($2 =="FP" || $2 =="RFP"){next} 1' Input_file

Output will be as follows.

12
11

Thanks,
R. Singh

1 Like

You could also try:

awk 'BEGIN{d["FP"];d["RFP"]}!($2 in d)' file

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

2 Likes

Hello Don,

Thank you for nice code, I think as by typo a " is missed in "RFP" .

awk 'BEGIN{d["FP"];d["RFP"]}!($2 in d)' file

Thanks,
R. Singh

3 Likes

Yes. Thank you for noticing. I have updated post #3 to fix the typo.

2 Likes

Thank you both :).

Wouldn't

grep -v "FP$" file
12
11

do?

1 Like