Skip to main content

egrep

Explanation

The egrep command is equivalent to grep -E. It treats the pattern as an extended regular expression (ERE). This allows for more advanced pattern matching using metacharacters like +, ?, |, and () without needing to escape them with backslashes as you would in standard grep. Note that egrep is deprecated in favor of grep -E on modern systems, but it's still widely used.

Basic Syntax

egrep [OPTION]... PATTERNS [FILE]...

Common Flags and Options

(Shares most options with standard grep)

FlagDescription
-i, --ignore-caseIgnore case distinctions.
-v, --invert-matchSelect non-matching lines.
-r, --recursiveRead all files under each directory recursively.

Real-world Examples

  1. Search for multiple alternative words (OR operator):

    egrep "error|warning|critical" /var/log/syslog
  2. Match patterns using extended metacharacters:

    egrep "go+d" file.txt  # Matches "god", "good", "goood", etc.