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
  • 27,777
  • 43
  • 130
  • 199

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
  • 50,672
  • 41
  • 197
  • 360
rush
  • 27,055
  • 7
  • 87
  • 112
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
  • 1
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
  • 922
  • 1
  • 12
  • 17
-1

You can use egrep instead:

cat /var/log/apache2/access.log|egrep -i 'spider|bot'
BitsOfNix
  • 5,057
  • 2
  • 25
  • 34