unix - awk : lines in file.txt that match any of the strings in file -
i have 2 separate .txt files:
list.txt, containing list of strings:
string1 string2 string3
and entries.txt, containing different lines 7 fields
name field2 field3 field4 field6 string1 field8
i need lines entries.txt 7th fields == 1 of lines in list.txt.
i know grep, grep -f list.txt entries.txt
, need in 7th field, wanted use awk.
so awk '$7==$(any string list.txt)'
how can write $(any string list.txt)
part?
try awk one-liner:
awk 'nr==fnr{a[$0];next}$7 in a' list.txt entries.txt
didn't test, should work requirement.
note : $6 or $7 ?
you said in question, should $7
, used $7
. @ example, seems should $6
? anyway, change column index yourself.
Comments
Post a Comment