«

»

Jul 03

Grep for Multiple Words

You can grep for two (or more) words at once.

  • For example, create a file containing:
One
Two
Three
Four
Five
  • Then use the following grep command (the -E option enables extended regular expressions, which lets you use the | as an “or” operator):
grep -E 'One|Two|Three' file.txt
  • Output is:
One
Two
Three

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>