What is the practical usage difference between "grep -e" and "grep"?
I have read the manual, but still I am not sure how it works. It says
-e pattern
,--regexp=pattern
Specify a pattern used during the search of the input: an input line is selected if it matches any of the specified patterns. This option is most useful when multiple
-e
options are used to specify multiple patterns, or when a pattern begins with a dash (‘-
’).
But I don't understand how this is different from any regular grep without -e
.
Here is the code I used to figure that out:
apple@apples-MacBook-Pro ~ % cat testgrep
warning
critical
error
passage
warning|critical
apple@apples-MacBook-Pro ~ % grep -e "warning|critical" testgrep
warning|critical
apple@apples-MacBook-Pro ~ % grep "warning|critical" testgrep
warning|critical
apple@apples-MacBook-Pro ~ % grep -e 'warning|critical' testgrep
warning|critical
apple@apples-MacBook-Pro ~ % grep 'warning|critical' testgrep
warning|critical
apple@apples-MacBook-Pro ~ % grep -e "warning\|critical" testgrep
warning
critical
warning|critical
apple@apples-MacBook-Pro ~ % grep -e 'warning\|critical' testgrep
warning
critical
warning|critical
apple@apples-MacBook-Pro ~ %
As you can see, they seem to behave in exactly the same manner. Is my understanding correct that they are pretty much the same thing except you can use -e
to search multiple patterns at the same time, just like you can with the |
operator?
Solution 1:
When I run
grep -e "search1" -e "search2"
Grep searches for both term 1 and term 2 (ie it returns lines matching either search 1 or search 2 or both), where as running the same command without -e errors - ie the -e allows for multiple different patterns to be specified seperately.