How do I match all lines not matching a particular pattern using grep? I tried this:
grep '[^foo]'
How do I match all lines not matching a particular pattern using grep? I tried this:
grep '[^foo]'
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
-e option can be used: grep -v -e 'negphrase1' -e 'negphrase2'grep -v 'negphrase1|negphrase2|negphrase3'-E works, i.e. grep -vE 'negphrase1|negphrase2|negphrase3'grep "" /dev/null * | grep foo | grep -v bar | cut -d: -f1 | sort -u (why the first grep?, there's always a way :))You can also use awk for these purposes, since it allows you to perform more complex checks in a clearer way:
Lines not containing foo:
awk '!/foo/'
Lines containing neither foo nor bar:
awk '!/foo/ && !/bar/'
Lines containing neither foo nor bar which contain either foo2 or bar2:
awk '!/foo/ && !/bar/ && (/foo2/ || /bar2/)'
And so on.
grep. Why is this upvoted?awk capabilities and providing an alternate solution that provides the same result is helpful./ /, so that Awk sees is as a string. Otherwise, it will treat timeshift and the other values as variable names. All together, you need to use awk '!/timeshift/ && !/icon/ && !/Papirus/ or using some regex-fu awk '!/(timeshift|icon|Papirus)/'.In your case, you presumably don't want to use grep, but add instead a negative clause to the find command, e.g.
find /home/baumerf/public_html/ -mmin -60 -not -name error_log
If you want to include wildcards in the name, you'll have to escape them, e.g. to exclude files with suffix .log:
find /home/baumerf/public_html/ -mmin -60 -not -name \*.log
mmin to search for files modified within 60 mins, use -type f too as mentioned here stackoverflow.com/a/33410471/2361131