grep exclude multiple strings

Filtering out multiple lines with grep:

Put these lines in filename.txt to test:

abc
def
ghi
jkl

grep command using -E flag with a pipe between tokens in a string:

grep -Ev 'def|jkl' filename.txt

prints:

abc
ghi

egrep using -v flag with pipe between tokens surrounded by parens:

egrep -v '(def|jkl)' filename.txt

prints:

abc
ghi

Or if stacking -e flags through grep parameters is okay (credit -> @Frizlab):

grep -Fv -e def -e jkl filename.txt

prints:

abc
ghi

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)