Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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