File comparisons using awk: Match columns
File3
a c e
File4
a 1 b 2 c 3 d 4 e 5
the one liner for comparing the first field of file4 with the first field of file3 is:
awk 'FNR==NR{a[$0];next}($1 in a)' file3 file4
and the output is:
a 1 c 3 e 5
And if you want to remove the lines which match just change the above mentioned command by adding a !
awk 'FNR==NR{a[$0];next}!($1 in a)' file3 file4
.png)







I am a software programmer working in India. I usually like to blog in my free time.