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?

  • 10
    grep -v pattern files*
    – lcd047
    May 16, 2015 at 18:49
  • @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
    Yes, he beat me of a few seconds :)
    – dr_
    May 18, 2015 at 7:27

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 
  • 8
    The long form of the flag -v is --invert-match. Aug 2, 2018 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.