Say I'm printing out a long series of strings, and instead of only showing lines containing a certain pattern (which one uses "grep" to do), how do I filter out certain patterns?

  • 11
    grep -v pattern files*
    – lcd047
    May 16, 2015 at 18:49
  • 1
    @lcd047 - Thanks! I guess I should have read the instruction for grep, rather than look for a separate command. Btw, since you commented before the other answerer did, I'd accept your answer if you posted it as one.
    – Alec
    May 16, 2015 at 19:24

1 Answer 1


You still use grep... with the -v option, which tells grep to print only those lines which do not match the pattern:

grep -v pattern myfile 

The long form of the -v option is --invert-match (mnemonic: "invert match").

  • 8
    The long form of the flag -v is --invert-match. Aug 2, 2018 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .