Compare files by lines and columns

Inspired by the extremely short awk code from Ygor on this post I wanted to compare two files on only one field. I can't get it to work. Can anybody help on explaining the code and fix the code?

My code which does not work:

awk 'BEGIN{a[$1]=1};a[$1]!=1' file1.txt file2.txt >outfile.txt

file1.txt
\mgm\file1.pdf
\mgm\file3.pdf
\mgm\file6.pdf
\mgm\file7.pdf
\mgm\file8.pdf

file2.txt
\mgm\file2.pdf
\mgm\file3.pdf
\mgm\file6.pdf
\mgm\file7.pdf
\mgm\file9.pdf

Outfile.txt
\mgm\file2.pdf
\mgm\file9.pdf

awk 'NR==FNR{a[$1];next}!($1 in a)' file1.txt file2.txt > Outfile.txt
1 Like