Regex – Negative Matching Using Grep (Exclude Lines Containing Specific Text)

grepregex

How do I match all lines not matching a particular pattern using grep? I tried this:

grep '[^foo]'

Best Answer

grep -v is your friend:

grep --help | grep invert  

-v, --invert-match select non-matching lines

Also check out the related -L (the complement of -l).

-L, --files-without-match only print FILE names containing no match

Related Question