18

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?

  • 8
    grep -v pattern files* – lcd047 May 16 '15 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 '15 at 19:24
  • 1
    Yes, he beat me of a few seconds :) – dr01 May 18 '15 at 7:27
26

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 
  • 3
    The long form of the flag -v is --invert-match. – Patrick Dark Aug 2 '18 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.