grep -e: Match Multiple Patterns at Once
grep -e adds a pattern; repeating -e matches a line if any of the patterns hit.
When you want to catch several distinct strings, repeated -e flags are clearer than a single alternation regex, and -e is also how you search for a pattern that starts with a dash.
What it does
grep -e PATTERN (--regexp) specifies a pattern explicitly; multiple -e flags act as a logical OR, so a line matches if it matches any pattern. -e is also required when a pattern begins with -, since otherwise grep treats it as an option. It works with -E, -F, and -i.
Common usage
# match any of several log levels
grep -e ERROR -e FATAL -e PANIC app.log
# search for a string that starts with a dash
grep -e "--deprecated-flag" config.txt
# combine with fixed strings
grep -F -e "10.0.0.1" -e "192.168.1.1" access.logOptions
| Flag | What it does |
|---|---|
| -e PATTERN | Add a pattern (repeatable, logical OR) |
| -E | Treat each -e pattern as extended regex |
| -F | Treat each -e pattern as a fixed string |
| -f FILE | Read patterns from a file instead |
In CI
Use repeated -e to assemble an allow/deny list of log markers without building a fragile regex. When a value you search for could begin with - (a CLI flag, a negative number), -e (or --) prevents grep from misreading it as an option.
Common errors in CI
"grep: invalid option -- 'X'" when searching for a string that starts with a dash means you need grep -e "-X" or grep -- "-X". Mixing -e patterns with a trailing bare pattern argument is easy to get wrong; once you use -e, give every pattern via -e. For many patterns, prefer -f with a file.