↑↓ move Enter open Esc close

How to Search for Multiple Patterns with grep

Match several words with grep using -e or extended regular expressions.

Log searches often need more than one term. grep supports alternatives with extended regular expressions or repeated -e options.

Step by step

1 Match either pattern

$ grep -E "error|warning" app.log

The | operator means OR in an extended regular expression.

2 Use several literal patterns

$ grep -e ERROR -e FATAL app.log

Repeat -e to provide independent patterns.

3 Ignore case too

$ grep -Ei "error|warning" app.log

Combine -E and -i for flexible matching.

4 Print only the match

$ grep -Eo "error|warning" app.log

The -o option prints only the matching part.

Tips worth knowing

Frequently asked questions

How do I grep for two words?

Use `grep -E "word1|word2" file` for OR matching.

What does grep -E do?

It enables extended regular expressions, including `|`.

The commands behind it

Concepts involved: Regular expression

More how-to guides