egrep - search a file for a pattern using full regular expressions


     Full Regular Expressions
     Extended Regular Expressions
Environment Variables
See Also


/usr/5bin/egrep [-e pattern_list ...] [-f pattern_file] [-bchilnrRvz] [pattern_list] [file ...]

/usr/5bin/posix/egrep -e pattern_list ... [-f pattern_file] [-c|-l|-q] [-bhinrRsvxz] [file ...]

/usr/5bin/posix/egrep -f pattern_file [-e pattern_list ...] [-c|-l|-q] [-bhinrRsvxz] [file ...]

/usr/5bin/posix/egrep [-c|-l|-q] [-bhinsrRvxz] pattern_list [file ...]


The egrep command searches the lines of the specified files (or of standard input) for occurrences of pattern. The default behavior is to print each matching line to standard output.

The /usr/5bin/egrep command accepts full regular expressions; it uses a deterministic algorithm with moderate space requirements.

The /usr/5bin/posix/egrep command accepts extended regular expressions. It uses a deterministic algorithm with moderate space requirements unless the expression includes multi-character collating elements, which cause the use of a nondeterministic algorithm.

/usr/5bin/s42/egrep and /usr/5bin/posix2001/egrep are identical to /usr/5bin/posix/egrep.

    Full Regular Expressions

In the following description 'character' excludes newline:
1. A \ followed by a single character matches that character.
2. The character ^ ($) matches the beginning (end) of a line as an anchor.
3. A . matches any character.
4. A single character not otherwise endowed with special meaning matches that character.
5. A string enclosed in brackets [] forms a bracket expression that matches any single character from the string. Ranges of ASCII character codes may be abbreviated as in 'a-z0-9'. A ] may occur only as the first character of the string. A literal - must be placed where it can't be mistaken as a range indicator.
6. A regular expression followed by * (+, ?) matches a sequence of 0 or more (1 or more, 0 or 1) matches of the regular expression.
7. Two regular expressions concatenated match a match of the first followed by a match of the second.
8. Two regular expressions separated by | or newline match either a match for the first or a match for the second (alternation).
9. A regular expression enclosed in parentheses () matches a match for the regular expression (grouping).

The order of precedence of operators is [] then () then *+? then concatenation then | and newline.

    Extended Regular Expressions

Extended Regular Expressions add the following features to Full Regular Expressions:
10. A regular expression followed by {m,n} forms an interval expression that matches a sequence of m through n matches, inclusive, of the regular expression. The values of m and n must be non-negative and smaller than 255. The form {m} matches exactly m occurrences, {m,} matches at least m occurrences.
11. In bracket expressions as described in 5., the following character sequences are considered special:
Character class expressions of the form [:class:]. In the C LC_CTYPE locale, the classes


are recognized; further locale-specific classes may be available. A character class expression matches any character that belongs to the given class in the current LC_CTYPE locale.

Collating symbol expressions of the form [.c.], where c is a collating symbol in the current LC_COLLATE locale. A collating symbol expression matches the specified collating symbol.
Equivalence class expressions of the form [=c=], where c is a collating symbol in the current LC_COLLATE locale. An equivalence class expression matches any character that has the same collating weight as c.
The order of precedence of operators is [==] [::] [..] then [] then () then *+? {m,n} then concatenation then ^ $ then | and newline.
Care should be taken when using the characters $ * [ ^ | ? ' " ( ) and \ in the expression as they are also meaningful to the Shell. It is safest to enclose the entire expression argument in single quotes ' '.
Both /usr/5bin/egrep and /usr/5bin/posix/egrep accept the following options:
-b Each line is preceded by the block number on which it was found. This is sometimes useful in locating disk block numbers by context. Block numbers start with 0.
-c Only a count of matching lines is printed.
-e pattern_list
  Specifies one or more patterns, separated by newline characters. A line is selected if one or more of the specified patterns are found.
-f pattern_file
  One or more patterns, separated by newline characters, are read from pattern_file. If multiple -e or -f options are supplied to /usr/5bin/posix/egrep, all of the pattern lists will be evaluated.
-h Normally, the name of each input file is printed before a match if there is more that one input file. When this option is present, no file names are printed.
-i Upper- and lowercase differences are ignored when searching matches.
-l The names of files with matching lines are listed (once) separated by newlines.
-n Each line is preceded by its line number in the file. Line numbers start with 1.
-v All lines but those matching are printed.
The following options are supported by /usr/5bin/posix/egrep only:
-q Do not write anything to standard output.
-s Error messages for nonexistent or unreadable files are suppressed.
-x Consider only lines consisting of the pattern as a whole, like a regular expression surrounded by ^ and $.
The following options are supported as extensions:
-r With this option given, egrep does not directly search in each given file that is a directory, but descends it recursively and scans each regular file found below it. Device files are ignored. Symbolic links are followed.
-R Operates recursively as with the -r option, but does not follow symbolic links that point to directories unless if they are explicitly specified as arguments.
-z If an input file is found to be compressed with compress(1), gzip(1), or bzip2(1), the appropriate compression program is started, and egrep searches for the pattern in its output.


  See locale(7).
  Affects the collation order for range expressions, equivalence classes, and collation symbols in extended regular expressions.
  Determines the mapping of bytes to characters in both full and extended regular expressions, the availability and composition of character classes in extended regular expressions, and the case mapping for the -i option.


ed(1), fgrep(1), grep(1), sed(1), locale(7)


Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files.


If a line contains a NUL character, only matches up to this character are found with /usr/5bin/posix/egrep. The entire matching line will be printed.

The LC_COLLATE variable has currently no effect. Ranges in bracket expressions are ordered as byte values in single-byte locales and as wide character values in multibyte locales; equivalence classes match the given character only, and multi-character collating elements are not available.

For portable programs, restrict textual data to the US-ASCII character set, set the LC_CTYPE and LC_COLLATE variables to 'C' or 'POSIX', and use the constructs in the second column instead of the character class expressions as follows:


<tab>, <space>, <vt>, <ff>, and <cr> indicate inclusion of a literal tabulator, space, vertical tabulator, formfeed, or carriage return character, respectively. Do not put the <vt>, <ff>, and <cr> characters into the range expression for the space class unless you actually want to match these characters.

Interval expressions were newly introduced with extended regular expressions and cannot be used in portable programs. To put a literal '{' character into an expression, use [{].

Heirloom Toolchest EGREP (1) 8/14/05
Generated by a modified version of manServer 1.07 from egrep.1 using man macros with tbl support.