Similar to the diff
options you could use the comm
command with the process substitutions and sort
(comm
requires the files it operates on be sorted). This would let you focus on just the common lines, just the lines that are in one file or the other by using -1
to supress lines only in the first file, -2
to suppress lines only in the second file or -3
to suppress lines in both, so to see all lines that are only in the first file and not the second you could do
comm -23 <(sort file1) <(sort file2)
of course, if you want that you could also consider using grep
like
grep -vFxf file2 file1
which will treat the lines in file2
as patterns and only print the lines from file1 which have no matches (-v
) when treating the lines from (-f
) file2
as fixed strings (-F
) that must match the entire line (-x
).
The grep
solution has the advantage of not needing to sort the files, but it only checks for lines in one of the files that are not in the other, not in both directions at once.