Deleting lines from one file which are in another file

grep -v -x -f f2 f1 should do the trick.

Explanation:

  • -v to select non-matching lines
  • -x to match whole lines only
  • -f f2 to get patterns from f2

One can instead use grep -F or fgrep to match fixed strings from f2 rather than patterns (in case you want remove the lines in a “what you see if what you get” manner rather than treating the lines in f2 as regex patterns).

Leave a Comment