If you don't need to preserve the order, you could use the comm
command like:
comm -13 <(sort file1) <(sort file2)
comm
compares 2 sorted files and will print 3 columns of output. First is the lines unique to file1, then lines unique to file2 then lines common to both. You can supress any columns, so we turn of 1 and 3 in this example with -13
so we will see only lines unique to the second file.
or you could use grep
:
grep -wvFf file1 file2
Here we use -f
to have grep get its patterns from file1
. We then tell it to treat them as fixed strings with -F
instead of as patterns, match whole words with -w
, and print only lines with no matches with -v