Reference: egrep
Author: Daniel Gilly & the Staff of O'Reilly & Associates
Date: 1998-08-06T21:52:44Z

#

| Chapter 2 UNIX Commands |

## egrep

    egrep [options] [regexp] [files]

Search one or more `files` for lines that match a regular expression `regexp`. egrep doesn't support the metacharacters \(, \), `\n`, \<, \>, \{, or \}, but does support the other expressions, as well as the extended set +, ?, |, and ( ). Remember to enclose these characters in quotes. Regular expressions are described in Section 6. Exit status is 0 if any lines match, 1 if not, and 2 for errors. See also grep and fgrep. egrep typically runs faster than those.

### Options

-b

  Precede each line with its block number.

-c

  Print only a count of matched lines.

-e `regexp`

  Use this if `regexp` begins with `-`.

-f `file`

  Take expression from `file`.

-h

  List matched lines but not filenames (inverse of -l).

-i

  Ignore uppercase and lowercase distinctions.

-l

  List filenames but not matched lines.

-n

  Print lines and their line numbers.

-s

  Silent mode: print only error messages, and return the exit status.

-v

  Print all lines that `don't` match `regexp`.

### Examples

Search for occurrences of `Victor` or `Victoria` in `file`:

>     egrep 'Victor(ia)*' file
>     egrep '(Victor|Victoria)' file

Find and print strings such as `old.doc1` or `new.doc2` in `files`, and include their line numbers:

>     egrep -n '(old|new)/.doc?' files

Reference: edit |  | Reference: env