egrep
Linux · Text · reference only
What it does
Searches for lines matching an extended regular expression. It is equivalent to grep -E.
Syntax
egrep [opciones] patrón [fichero...]
Options and parameters
-iIgnores the difference between upper and lower case.
-vInverts the search: shows the lines that do not match.
-nPrefixes each match with its line number.
-cShows only how many lines match.
-oShows only the part of the line that matches.
-rSearches recursively inside directories.
Usage examples
egrep 'error|warn' /var/log/syslogShows the lines that contain error or warn.
egrep -i '^(ana|luis):' /etc/passwdShows the ana or luis accounts, ignoring case.
egrep -c '[0-9]{3}' datos.txtCounts the lines with at least three consecutive digits.
egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' acceso.logExtracts the IP addresses from a log.
Notes and common mistakes
- It is obsolete: recent GNU grep versions warn and recommend writing grep -E.
- With -E you can use |, +, ? and {} without escaping them.