egrep Command
The egrep command searches for patterns in text using extended regular expressions. It's equivalent to grep -E and provides more powerful pattern matching capabilities than basic grep.
Syntax
Description
The egrep command uses extended regular expressions (ERE) to search for patterns in files or input streams. It supports advanced regex features without requiring escape characters.
Key features:
- Extended regular expression support
- Alternation with | (pipe) operator
- Quantifiers: + (one or more), ? (zero or one)
- Grouping with parentheses ()
- Case-sensitive and case-insensitive matching
Common Options
| Option | Description |
|---|---|
-i |
Case-insensitive matching |
-v |
Invert match (show non-matching lines) |
-n |
Show line numbers |
-c |
Count matching lines |
-l |
Show only filenames with matches |
-r |
Recursive search in directories |
-w |
Match whole words only |
-o |
Show only matching parts |
Examples
Basic pattern search
Searches for lines containing "error" in logfile.txt
Alternation (OR operator)
Searches for lines containing any of the three patterns
Case-insensitive search
Searches for "error" regardless of case
Show line numbers
Shows line numbers along with matching lines
Count matches
Counts the number of matching lines
One or more quantifier
Matches both "color" and "colour"
Plus quantifier
Matches one or more digits
Grouping with parentheses
Matches HTTP and HTTPS URLs
Word boundaries
Matches "test" as a whole word only
Recursive search
Recursively searches for pattern in all files
Show only matches
Extracts email addresses from text