0

How do I search in a textfile with grep for the occurrence of a word or another word?

I want to filter the apache log file for all lines including "bot" or "spider"

cat /var/log/apache2/access.log|grep -i spider

shows only the lines including "spider", but how do I add "bot"?

rubo77
  • 28,966

4 Answers4

5

use classic regex:

grep -i 'spider\|bot'

or extended regex (or even perl regex -P):

grep -Ei 'spider|bot'

or multiple literal patterns (faster than a regular expression):

grep -Fi -e 'spider' -e 'bot'
l0b0
  • 51,350
rush
  • 27,403
1
cat /var/log/apache2/access.log | grep -E 'spider|bot'

With the -E option you activate extended regular expression, where you can use | for an logical OR.

Besides, instead of invoking another process - cat - you can do this with

grep -E 'spider|bot' /var/log/apache2/access.log
faisch
  • 71
0

$ cat /var/log/apache2/access.log|grep -i 'spider\|bot'

The above will do the job.

You can also use egrep

$ cat /var/log/apache2/access.log|egrep -i 'spider|bot'

egrep is extended grep (grep -E). You will not have to use \ before | if you use egrep.

mezi
  • 942
-1

You can use egrep instead:

cat /var/log/apache2/access.log|egrep -i 'spider|bot'
BitsOfNix
  • 5,117