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

  • -i

    Ignores the difference between upper and lower case.

  • -v

    Inverts the search: shows the lines that do not match.

  • -n

    Prefixes each match with its line number.

  • -c

    Shows only how many lines match.

  • -o

    Shows only the part of the line that matches.

  • -r

    Searches recursively inside directories.

Usage examples

  • egrep 'error|warn' /var/log/syslog

    Shows the lines that contain error or warn.

  • egrep -i '^(ana|luis):' /etc/passwd

    Shows the ana or luis accounts, ignoring case.

  • egrep -c '[0-9]{3}' datos.txt

    Counts the lines with at least three consecutive digits.

  • egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' acceso.log

    Extracts 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.

Related commands