I'm console newbie. As I know, matching multiple patterns like this:
aaa|bbb
But, | character is pipe on console, so how can I specify those multiple patterns for grep?
I'm console newbie. As I know, matching multiple patterns like this:
aaa|bbb
But, | character is pipe on console, so how can I specify those multiple patterns for grep?
You can escape the pipe and put the pattern in quotes:
or use
-E
:or
Put "" between your pattern, like
egrep "toto|name"
Or you go
to grep for aaa or bbb in filename, case insensitively.
Lastly, you can put your patterns into a file, and use the -f flag. So
Make sure there are no empty lines, though.grep -f patternlist.txt files
. Where patternlist.txt is simply:--Christopher Karel
Enclose your pattern in single quotes:
Should your pattern include an apostrophe, enclose it in double quotes:
If it contains both single and double quotes, enclose it in double quotes and prefix with a backslash the characters ", $, ` and \:
The final example of
C:\AUTOEXEC.BAT
takes into account that backslash is special both to the shell and to the regular expression syntax of egrep.PS: The bash quoting page is a must-read.
egrep "aaa|bbb|ccc" <file>
will find all rows with either aaa OR bbb OR ccc in the file
egrep -i "aaa|bbb|ccc" <file>
will find
aaa
ORaaA
ORaAa
ORAaa
ORaAA
ORAAa
ORAAA
OR ... and the same for every other string enumerated between the pipe|
characters.