Reputation: 2203
I want to ask a question regarding the strings matching in awk language. I have multiple strings in a file
like :
abc
def
ghi
jkl
mno
.
.
.
I want to match these strings in the other text file.
Is there an easy way to do that using awk? Thanks for any help.
Upvotes: 1
Views: 812
Reputation: 2203
If string from 1st column of file1 has to matched to 4th column of another file2 and all the lines (matched only) are to printed. than i guess this is an easiest way to do in awk.
awk -F "field seperater" '{a[$1=1]} a[$4]' file1 file2.
Upvotes: 0
Reputation: 77175
Yes, there is an easy way of doing this in awk.
awk 'FNR==NR{a[$0];next}($0 in a)' file_1 file_2
where file_1
is your string file and file_2
is your search file.
Upvotes: 4