How to grep several pattern at once?

2

I want to get every line that match there pattern:

  • something
  • someplace
  • somewhere

from /data/rawlog.txt

I try this command, but failed:

grep -e "[something|someplace|somewhere]" /data/rawlog.txt

Anyone know what goes wrong?

ariefbayu

Posted 2010-06-24T05:11:18.143

Reputation: 931

Answers

7

First, you don't need the brackets. Second, you need extended regular expressions or escape the pipes. One of this should work:

egrep -e "something|someplace|somewhere" /data/rawlog.txt
grep -e "something\|someplace\|somewhere" /data/rawlog.txt

If you want to place something outside of the fork, don't forget to group it. For example, if you want these patterns to occur only at the end of the line:

egrep -e "(something|someplace|somewhere)$" /data/rawlog.txt

Note that parenthesis also need egrep or escaping.

petersohn

Posted 2010-06-24T05:11:18.143

Reputation: 2 554