Grep options

OR

1. Grep OR Using \|

grep 'pattern1\|pattern2' filename

2. Grep OR Using -E

grep -E 'pattern1|pattern2' filename

3. Grep OR Using egrep

egrep 'pattern1|pattern2' filename

4. Grep OR Using grep -e

grep -e pattern1 -e pattern2 filename

AND

5. Grep AND using -E ‘pattern1.*pattern2′

There is no AND operator in grep. But, you can simulate AND using grep -E option.

grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename

6. Grep AND using Multiple grep command

grep -E 'pattern1' filename | grep -E 'pattern2'

NOT

7. Grep NOT using grep -v

grep -v 'pattern1' filename

8. Grep but NOT

egrep 'Manager|Developer' employee.txt | grep -v Sales

Exacte woord match en woord count

grep -o -w [Vv]ader ./liefdesbrief.txt | wc -w

Show only filenames (-l) containing pattern, Exclude directory (--e) from recursive (-R)

grep -l -R --exclude-dir=./httpdocs/wp-content/uploads/quarantine 'ynbhxxvtmh' ./