UNIX: excluding patterns, contained in a file, from another file with grep

grep

I have a txt file that contains the patterns I would like to exclude from a file. Is there a way to chain grep -f and grep -v?

Thanks

Best Answer

You can use the options together like:

grep -vf exclude.txt file.txt

Example:

$ cat exclude.txt 
3

$ cat file.txt
1
3
4
1
4
3
1
2

$ grep -vf exclude.txt file.txt 
1
4
1
4
1
2
Related Question