Friday, October 7, 2022

[SOLVED] Negative matching using grep (match lines that do not contain foo)

Issue

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

grep '[^foo]'

Solution

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



Answered By - Motti
Answer Checked By - Marie Seifert (WPSolving Admin)