COHERENT manpages

This page displays the COHERENT manpage for egrep [Extended pattern search].

List of available manpages
Index


egrep -- Command

Extended pattern search
egrep [-Abcefhily] [pattern] [file ...]

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  ed,  egrep  can also  process  patterns  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.

[chars]
    Match any one of the enclosed chars. Ranges of letters or digits may be
    indicated using `-'.

[^chars]
    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 metacharacters:

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

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

Options

The following lists the available options:

-A Write  all lines  in which  expression is found  into a  temporary file.
   Then, call  COHERENT with its  error option to process  the source file,
   with the  contents of the  temporary file serving as  an ``error'' list.
   This option  resembles the  -A option  to the cc  command, and  lets you
   build a  COHERENT script to make systematic changes  to the source file.
   To  exit COHERENT  and prevent egrep  from searching  further, <ctrl-
   U> <ctrl-X> <ctrl-C>.

   Unlike cgrep,  egrep only  matches patterns that  are on a  single line.
   Some  systems have  a  context grep  cgrep)  that works  like egrep  but
   displays  lines  found  in context.   The  COHERENT  egrep  -A not  only
   displays lines in context, via COHERENT, it lets you edit them.

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

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

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

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

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

-i Ignore case when matches alphabetic letter in pattern.  egrep takes case
   into account, even with this option, when you prefix a letter in pattern
   with `\'.

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

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

-s Suppress all output, just return exit status.

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

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

Limits

The COHERENT implementation of egrep sets the following limits on input and
output:

     Characters per input record        512
     Characters per output record       512
     Characters per field               512

See Also

awk,
cgrep,
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

For  matching  patterns in  C  programs, the  command  cgrep is  preferred,
because it is optimized to recognize C-style expressions.

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  immediately.  This means that
egrep  is  is  much faster  than  grep,  often by  more  than  an order  of
magnitude,  and  is  considerably  faster  than  earlier  pattern-searching
commands, on almost any length of file.