Summary: How to use the Linux egrep command with multiple regular expressions (regex patterns).
As a quick note here today, I just used the Linux
egrep command to perform a case-insensitive search on multiple regular expressions (regex patterns). Really, what I did was a little more complicated:
locate -i calendar | grep Users | egrep -vi 'twiki|gif|shtml|drupal-7|java|PNG'
As you can see from that command, I did this:
- Used to
locatecommand with the case-insensitive option to find all files with the string "calendar" in them.
- Used the
grepcommand so the output would only display files and directories with the string "Users" in them.
- Used the
egrepcommand with multiple regex patterns to reduce the output much more. I used the
-vargument to perform the "opposite" meaning of a normal
egrepcommand, so strings with these patterns were not shown; and also used the
-iargument to perform a case insensitive
While my original
locate -i calendar command shows nearly 3,000 files, the
locate command combined with
egrep in this manner shows only 15 files.
An easier egrep command
Before I go away, here's an easier
egrep command to look at:
egrep 'apple|banana|orange' *
That egrep command searches for those three strings (regular expressions, really) in all files in the current directory. This next command does the same thing, but in a case-insensitive manner:
egrep -i 'apple|banana|orange' *