GNU grep (et j'imagine que d'autres aussi) peut prendre le format -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.)
Donc, tu pourrais faire ça :
grep -vFf file1 file2
Suivant Nicole Hamilton suggestion dans les commentaires, j'ai ajouté l'option '-F' qui permet à grep d'interpréter son PATTERN (dans ce cas, chaque ligne de file1) comme des chaînes fixes et non comme des expressions régulières :
-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.)
J'ai également écrit un PERL script avec quelques options supplémentaires :
$ 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