Grep options

Zie ook sort options :

[pvi@bl08204 ~]$ sort vs00153-outside.csv | uniq -c | sort -nr

182 73.149.77.1;dmz;151.236.132.36;443
181 75.186.76.212;dmz;151.236.132.36;443
181 72.193.181.10;dmz;151.236.132.36;443

zgrep

zgrep 193.172.213. ./fws*.gz | grep -v -f /home/pvi/exclude_ip_dns-pub.txt | grep permitted

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 and exclude directory from recursive (-R --exclude-dir=) search

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