There are two ways to do this. With comm
or with grep
, sort
, and uniq
.
comm
comm afile bfile
comm
compares the files and outputs 3 columns, lines only in afile
, lines only in bfile
, and lines in common. The -1
, -3
switches tell comm
to not print out those columns.
grep
sort
uniq
grep -F -v -file bfile afile | sort | uniq
or just
grep -F -v -file bfile afile | sort -u
if your sort
handles the -u
option.
(note: the command fgrep
if your system has it, is equivalent to grep -F
.)