egrep
Search files for extended regular expression patterns
TLDR
View documentation for the original command
SYNOPSIS
egrep [OPTION...] [PATTERN] [FILE...]
PARAMETERS
-i, --ignore-case
Ignore case distinctions in PATTERN and input files
-v, --invert-match
Select non-matching lines
-w, --word-regexp
Select only matches that exactly match whole words
-x, --line-regexp
Select only matches that exactly match entire lines
-c, --count
Suppress normal output; print count of matching lines per file
-l, --files-with-matches
Suppress normal output; print names of files with matches
-L, --files-without-match
Suppress normal output; print names of files without matches
-n, --line-number
Prefix each line of output with 1-based line number
-b, --byte-offset
Prefix each line with 1-based byte offset
-H, --with-filename
Always print filename before matching lines
-h, --no-filename
Never print filename, even with multiple files
-r, -R, --recursive
Recursively search directories
-e PATTERN, --regexp=PATTERN
Use PATTERN as explicit search pattern
-f FILE, --file=FILE
Read patterns from FILE
-A NUM, --after-context=NUM
Print NUM lines of trailing context after each match
-B NUM, --before-context=NUM
Print NUM lines of leading context before each match
-C NUM, -NUM
Equivalent to --before-context=NUM and --after-context=NUM
-o, --only-matching
Show only the part of a matching line that matches PATTERN
DESCRIPTION
egrep (extended grep) is a powerful command-line tool for searching text files or input streams for lines matching a specified extended regular expression (ERE). Unlike basic grep, which uses basic regular expressions (BRE), egrep treats meta-characters like | (alternation), + (one or more), ? (zero or one), and parentheses () as grouping operators without requiring backslashes for escaping.
It processes one or more input files or standard input, printing matching lines to standard output by default. egrep is ideal for complex pattern matching in logs, code, configuration files, or data streams, supporting case-insensitive searches, counting matches, line numbering, and recursive directory traversal.
Key advantages include intuitive regex syntax for alternatives and repetitions, making it suitable for tasks like finding errors ('error|warn'), IP addresses ('([0-9]{1,3}\.){3}[0-9]{1,3}'), or multi-line patterns. Output can be customized with context lines, filenames, or offsets.
In modern Linux distributions, egrep is typically a symbolic link or alias to grep -E, providing identical functionality. It adheres to POSIX standards but extends with GNU-specific options for enhanced usability.
CAVEATS
egrep is deprecated in modern GNU grep (since v2.5.3); use grep -E instead for extended regex. Not suitable for very large files without streaming; patterns are compiled once per invocation.
EXTENDED REGEX FEATURES
Supports | (or), + (1+), ? (0|1), * (0+), () (grouping), {n,m} (repetition) without escapes.
COMMON EXAMPLES
egrep 'error|warning' /var/log/syslog
egrep -r -i 'TODO|FIXME' /src/dir
egrep -c '^From:' mbox
HISTORY
Introduced in early Unix System V (1980s) as an extension to grep for ERE support. Standardized in POSIX.1-2001. In GNU coreutils, deprecated favoring unified grep with -E flag; remains for backward compatibility.


