The command you have to use is not diff
but comm
comm -23 a.txt b.txt
By default, comm
outputs 3 columns: left-only, right-only, both. The -1
, -2
and -3
switches suppress these columns.
So, -23
hides the right-only and both columns, showing the lines that appear only in the first (left) file.
If you want to find lines that appear in both, you can use -12
, which hides the left-only and right-only columns, leaving you with just the both column.