Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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"?

share|improve this question

marked as duplicate by don_crissti, Anthon, manatwork, slm, Hauke Laging Jun 26 '13 at 12:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 5 down vote accepted

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'
share|improve this answer
+1 for covering multiple bases and also (implicitly) losing the cat. – tripleee Jun 26 '13 at 8:54
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
share|improve this answer

$ 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.

share|improve this answer

You can use egrep instead:

cat /var/log/apache2/access.log|egrep -i 'spider|bot'
share|improve this answer
egrep is the same as grep -E. … Direct invocation as … egrep … is deprecated” – man grep – manatwork Jun 26 '13 at 8:35
-1 The double pipe || means 'or', it's not a pipe at all. Also you might want to fix the UUCA. – tripleee Jun 26 '13 at 8:52
The double-pipe ignored, on some platforms grep -E is not available and egrep is the only option. – Johan Jun 26 '13 at 9:29
the double | was a mistype actually. – BitsOfNix Jun 26 '13 at 10:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.