

egrep                        Command                        egrep




Extended pattern search

eeggrreepp [_o_p_t_i_o_n ...] [_p_a_t_t_e_r_n] [_f_i_l_e ...]

egrep is  an extended and  faster version of  grep.  It  searches
each  file for  occurrences  of pattern  (also  called a  regular
expression).  If  no file is specified,  it searches the standard
input.  Normally, it prints each line matching the pattern.

***** Wildcards *****

The simplest patterns accepted by egrep are ordinary alphanumeric
strings.  Like  eedd, eeggrreepp can also  process _p_a_t_t_e_r_n_s that include
the following wildcard characters:

^   Match beginning  of line, unless it appears immediately after
    `[' (see below).

$   Match end of line.

*   Match zero or more repetitions of preceding character.

.   Match any character except newline.

[_c_h_a_r_s]
    Match any  one of the  enclosed chars.  Ranges  of letters or
    digits may be indicated using `-'.

[^_c_h_a_r_s]
    Match any character except one of the enclosed chars.  Ranges
    of letters or digits may be indicated using `-'.

\_c  Disregard special meaning of character c.

***** Metacharacters *****

In addition,  egrep accepts the  following additional metacharac-
ters:

|   Match  the preceding pattern  or the following  pattern.  For
    example, the  pattern cat|dog matches  either cat or  dog.  A
    newline within the pattern has the same meaning as `|'.

+   Match  one or more  occurrences of the  immediately preceding
    pattern  element; it  works like  `*',  except it  matches at
    least one occurrence instead of zero or more occurrences.

?   Match zero or one  occurrence of the preceding element of the
    pattern.

(...)
    Parentheses  may be  used  to group  patterns.  For  example,
    (Ivan)+ matches a sequence  of one or more occurrences of the
    four letters `I' `v' `a' or `n'.


COHERENT Lexicon                                           Page 1




egrep                        Command                        egrep




Because the metacharacters `*', `?', `$', `(', `)', `[', `]', and
`|'   are also  special to  the shell  sshh, patterns  that contain
those  literal characters  must  be quoted  by enclosing  pattern
within single quotation marks.

***** Options *****

The following lists the available options:

-bb  With  each output line,  print the block number  in which the
    line started (used to search file systems).

-cc  Print how many lines match, rather than the lines themselves.

-ee  The  next argument is  pattern (useful if  the pattern starts
    with `-').

-ff  The next argument is a  file that contains a list of patterns
    separated by newlines; there is no pattern argument.

-hh  When more than one  file is specified, output lines are norm-
    ally accompanied by the file name; -h suppresses this.

-ll  Print the name of  each file that contains the string, rather
    than the lines themselves.   This is useful when you are con-
    structing a batch file.

-nn   When a  line is  printed, also print  its number  within the
    file.

-ss  Suppress all output, just return exit status.

-vv  Print a line only if the pattern is not found in the line.

-yy  Lower-case letters in the pattern match lower-case and upper-
    case letters  on the input lines.  A  letter escaped with `\'
    in the pattern must be matched in exactly that case.

***** See Also *****

awk, commands, ed, expr, grep, lex, sed

***** Diagnostics *****

egrep  returns an  exit status  of zero for  success, one  for no
matches, and two for error.

***** Notes *****

Besides the  difference in the  range of patterns  allowed, egrep
uses a  deterministic finite automaton (DFA)  for the search.  It
builds the  DFA dynamically, so  it begins doing  useful work im-
mediately.  This  means that egrep  is is much  faster than grep,
often by  more than an  order of magnitude,  and is  considerably


COHERENT Lexicon                                           Page 2




egrep                        Command                        egrep



faster  than earlier  pattern-searching commands,  on  almost any
length of file.























































COHERENT Lexicon                                           Page 3


