Compare lines of two files, print lines unique to first file
Try this
$ join file1.txt file2.txt -v 1
$ man join
-a FILENUM
print unpairable lines coming from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2
-v FILENUM
like -a FILENUM, but suppress joined output lines
This is what comm
is for:
comm -- select or reject lines common to two files
You want
comm -23 "File 1" "File 2"
which will suppress output of lines only in file 2 and lines in both files, leaving only lines in file 1. More answers here on Greg Wooledge's wiki
You can use grep
:
grep -f file1.txt -vFx file2.txt
Notice the usage of the flags F, --fixed-strings
and x, --line-regexp
, to force the comparison to be performed considering the entire line.