How can I use grep to search for line with either 'res' or 'rep'?
I tried grep -e res|rep and grep -e "rep|rep" but neither worked.
You can also use -E option with grep, so there's no need to escape |, for example:
grep -E 'res|rep' file Or, you can use egrep, which is the same thing as grep -E:
egrep 'res|rep' file pmset -g sched | grep -E "shutdown|restart|sleep". (Neither did using egrep.) You need to escape the pipe character:
grep 'res\|rep' file or use multiple -e options:
grep -e 'res' -e 'rep' file The regex sort of way is:
EDIT grep -nis "re[sp]" <FILENAME>
This way you will be presented with all lines containing either "res" or "rep"
also note that -nis is in no way important here, I just like it that way... :)
re[sp] so that it is not accidentally expanded by the shell should there be files named res or rep. Multiple patterns can be specified by using the -e pattern or --regexp=pattern option instead of specifying the pattern inline.
grep -e res -e rep or
grep --regexp=res --regexp=rep Per the Linux grep man page (with formatting added):
-e PATTERNS,--regexp=PATTERNSUse
PATTERNSas the patterns. If this option is used multiple times […], search for all patterns given.
The pattern string used by grep treats the newline character as a pattern separator. Therefore, using a newline is one way to search for multiple patterns.
grep $'res\nrep' Per the Linux grep man page (with formatting added):
grep [OPTION...] PATTERNS [FILE...][…]
grepsearches forPATTERNSin eachFILE.PATTERNSis one or more patterns separated by newline characters, and grep prints each line that matches a pattern.