Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

ex(1)

fgrep(1)

grep(1)

regcmp(1)

sed(1)

sh(1sh)



EGREP(1)                COMMAND REFERENCE                EGREP(1)



NAME
     egrep - search a file for a pattern

SYNOPSIS
     egrep [ -E ] [ -b ] [ -c ] [ -e ] [ -h ] [ -l ] [ -n ] [ -s
     ] [ -v ] [ expression ]
     [ filename ... ]

DESCRIPTION
     Egrep searches the input files (standard input default) for
     lines matching an expression.  Normally, each line found is
     copied to the standard output.  Unless the -h option is
     given, the file name is shown if there is more than one
     input file.

     You may specify the expression on the command line or in a
     file.  If expression is given on the command line, it may be
     preceded by the flag -e. This is useful for specifying
     expressions that begin with '-'.  If the expression is
     contained in a file, you must specify the -f filename
     option.  If you don't specify the -e or -f flags, expression
     must follow all other options.

     Egrep patterns are full regular expressions; it uses a fast
     deterministic algorithm that sometimes needs exponential
     space.  Egrep accepts extended regular expressions.  In the
     following description `character' excludes newline:

          A \ followed by a single character other than newline
          matches that character.

          The character ^ matches the beginning of a line.

          The character $ matches the end of a line.

          A . (period) matches any character.

          A single character not otherwise endowed with special
          meaning matches that character.

          A string enclosed in brackets [] 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.

          A regular expression followed by an * (asterisk)
          matches a sequence of 0 or more matches of the regular
          expression.  A regular expression followed by a +
          (plus) matches a sequence of 1 or more matches of the
          regular expression.  A regular expression followed by a



Printed 4/6/89                                                  1





EGREP(1)                COMMAND REFERENCE                EGREP(1)



          ? (question mark) matches a sequence of 0 or 1 matches
          of the regular expression.

          Two regular expressions concatenated match a match of
          the first followed by a match of the second.

          Two regular expressions separated by | or newline match
          either a match for the first or a match for the second.

          A regular expression enclosed in parentheses matches a
          match for the regular expression.

     The order of precedence of operators at the same parenthesis
     level is [] then *+? then concatenation 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.

OPTIONS
     -E Print matching lines in the form :
        filename, line linenumber : matching line

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

     -c Only a count of matching lines is printed.

     -e expression
        Same as a simple expression argument, but useful when the
        expression begins with a '-'.

     -f filename
        The regular expression is taken from the filename.

     -h Suppress printing of file names if multiple files are
        given.

     -l The names of files with matching lines are listed (once)
        separated by newlines.  If this option is given when
        reading from standard input, egrep simply exits with a
        value of 1.

     -n Each line is preceded by its relative line number in the
        file.

     -s Silent mode. No error message is printed for nonexistent
        files (does not apply to regular expression file).

     -v All lines but those matching are printed.



Printed 4/6/89                                                  2





EGREP(1)                COMMAND REFERENCE                EGREP(1)



EXAMPLES
     The following example prints the number of lines in the file
     "example" that contain either the word "and" or the word
     "or". The word boundaries in this case are the beginning and
     end of the line, and spaces or tabs (^I).

          egrep -c '(^|[ ^I]+)(and|or)([ ^I]+|$)' example

     This example prints the lines in all of the files in the
     current directory which contain the sequence "number" with
     or without the 'n' capitalized, followed by a space and an
     integer. No file names are printed.

          egrep -h '[nN]umber [0-9]+' *

RETURN VALUE
     [0]            No errors occurred and at least one match was
                    found.

     [USAGE]        Incorrect command line syntax. Execution
                    terminated.

     [1]            No errors occurred but no matches were found.


     [NP_ERR]       An error occurred that was not a system
                    error.  Execution terminated.

     [P_ERR]        A system error occurred. Execution
                    terminated.  See intro(2) for more
                    information on system errors.

CAVEATS
     If one of the input files is the same as the output, as in
     the example ``egrep re * > out'', that input file is not
     searched in order to prevent problems.  No message is
     printed in this case.  If the old functionality is required,
     pipe the output through cat(1).

     The precedence of the output specification options is -c,
     -E, and -l, which turn off the -n and -b options and the
     printing of the file name and matching line.

     Tests show that egrep is the fastest of the pattern
     searching commands.

SEE ALSO
     ed(1), ex(1), fgrep(1), grep(1), regcmp(1), sed(1), and
     sh(1sh).






Printed 4/6/89                                                  3



%%index%%
na:264,87;
sy:351,472;
de:823,2544;3703,1096;
op:4799,1545;
ex:6680,663;
rv:7343,663;
ca:8006,814;
se:8820,223;
%%index%%000000000145

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026