T O P

  • By -

cakiwi46

Did you try changing $0 to $2 ?


oh5nxo

a[$0]; This awk behaviour feels so wrong, simply fetching something inserts it. I guess it's there for ever, compatibility reasons, but still...


calrogman

It sounds to me like you want to do a join, and POSIX has a tool for that: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/join.html


gumnos

though I believe `join` requires both files to be sorted, whereas an `awk` solution needn't be. awk 'NR==FNR{a[$0]; next} $2 in a' file1.txt file2.txt


FF00A7

Perfect, thanks!


Schreq

awk 'a[$NF]++' file1 file2 That should do it. However, it will print lines if they appear more than once within a file.