GNU grep (and I imagine others also) can take the -f
option:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty
file contains zero patterns, and therefore matches
nothing. (-f is specified by POSIX.)
So, you could do this:
grep -vFf file1 file2
Following Nicole Hamilton's suggestion in the comments, I have added the '-F' option which causes grep to interpret its PATTERN (in this case, each line in file1) as fixed strings and not regular expressions:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched. (-F is specified by
POSIX.)
I have also written a PERL script with a few more options:
$ list_compare.pl -h
USAGE: compare_lists.pl FILE1 FILE2
This script will compare FILE1 and FILE2, searching for the
contents of FILE1 in FILE2 (and NOT vice-versa). FILE one must
be one search pattern per line, the search pattern need only be
contained within one of the lines of FILE2.
OPTIONS:
-c : Print patterns COMMON to both files
-f : Search only the first characters (until the 1st space) of each line of
FILE2 for the search pattern given in FILE1. So, if FILE1 contains
"foo bar", only "foo" will be taken as a pattern (MUCH faster).
-d : Print duplicate entries
-m : Print patterns MISSING in FILE2 (default)
-h : Print this help and exit