Reputation: 61
I'm trying to compare two files (file1 and file2) and print the full lines from file1 that don't match the list from file2 - ideally in a new .txt file, however when I run awk it's not printing anything.
file1 example file2 example
12345 /users/test/Desktop 543252
54321 /users/test/Downloads 12345
0000 /users/test/Desktop 11111
0000
expected output
54321 /users/test/Downloads
The command I've tried is
awk 'NR==FNR{a[$1]++;next};a[$1] ==0' file1.txt file2.txt
ideally I'd like to be able to build this into a python program I'm writing (don't know if that's possible) if not I'd be happy for it to run through the linux terminal.
Any thoughts or pointers would be gratefully received.
Upvotes: 1
Views: 5293
Reputation: 16997
You have to correct your awk like below
awk 'FNR==NR{ a[$1]; next } !($1 in a)' file2 file1
Upvotes: 4
Reputation: 2091
You can get the expected output with grep
:
grep -vf file2 file1
Upvotes: 3