The comm
command takes two file arguments and prints three columns: lines unique to the first file, lines unique to the second file, and lines occurring in both files. So if you have two files where one is a copy of the other one plus a few lines, like this:
oldfile
:
line1
line2
line3
newfile
:
line1
line2
line3
line4
line5
you can use comm
as follows:
$ comm -13 oldfile newfile
line4
line5
where -13
stands for "suppress columns 1 and 3", i.e., print only lines unique to the second file.
comm
expects its inputs to be sorted and will complain if they aren't (at least the GNU version of comm
does), but if your files really are copies of each other plus extra lines in one of them, you can suppress that warning:
comm --nocheck-order -13 oldfile newfile
--nocheck-order
exists only in GNU comm
, which is part of the GNU coreutils (can be installed via homebrew, for example).
If the warning about the files being unsorted is a show stopper and the order of the output lines doesn't matter, you could also sort the input files:
comm -13 <(sort oldfile) <(sort newfile)