Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

awk(1)

ex(1)

sed(1)

sh(1)

GREP(1)                              BSD                               GREP(1)



NAME
     grep, egrep, fgrep - search a file for a pattern

SYNOPSIS
     grep [ option ] ...  expression [ file ] ...

     egrep [ option ] ...  [ expression ] [ file ] ...

     fgrep [ option ] ...  [ strings ] [ file ] ...

DESCRIPTION
     Commands of the grep family search the input files (the standard input is
     the default) for lines matching a pattern.  Normally, each line found is
     copied to the standard output.  Patterns used by grep are limited regular
     expressions in the style of ex(1); it uses a compact, non-deterministic
     algorithm.  Patterns used by egrep are full regular expressions; egrep
     uses a fast, deterministic algorithm that sometimes needs exponential
     space.  Patterns used by fgrep are fixed strings; it is fast and compact.

     In all cases, the filename is shown if there is more than one input file.
     Be careful about using the $ * [ ^ | (  ) and \ characters in expression,
     because they are also meaningful to the shell. It is safest to enclose
     the entire expression argument in single quotation marks (' ').

     fgrep searches for lines that contain one of the (newline-separated)
     strings.

     egrep accepts extended regular expressions.  In the following description
     character excludes newline:

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

          A ^ matches the beginning of a line.

          A $ 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.  You can abbreviate ranges of ASCII character codes, 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 for a
          range indicator.

          A regular expression followed by an * (asterisk) matches a sequence
          of zero or more matches of the regular expression.  A regular
          expression followed by a + matches a sequence of one or more matches
          of the regular expression.  A regular expression followed by a ?
          matches a sequence of zero or one 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.

OPTIONS
     -v        Print all lines but those matching.

     -x        Print only lines exactly matched in their entirety. (fgrep
               only).

     -c        Print only a count of matching lines.

     -l        List only the filenames with matching lines (once).  Separate
               the names with newlines.

     -n        Precede each line by its relative line number in the file.

     -b        Precede each line by the block number on which it was found.
               This option helps to locate disk block numbers by context.

     -i        Ignore the case of letters during comparisons - that is,
               uppercase and lowercase are considered identical (grep and
               fgrep only).

     -s        Silent mode. Print nothing except error messages.  This is
               useful for checking the error status.

     -w        Search for the expression as a word (as if surrounded by `\<'
               and `\>').  See ex(1)) for further details (grep only).

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

     -f file   Take the regular expression (egrep) or string list (fgrep) from
               the file.

DIAGNOSTICS
     Exit status is 0 if any matches are found; 1 if none; 2 if there are
     syntax errors or inaccessible files.

BUGS
     Lines are limited to 256 characters; longer lines are truncated.

SEE ALSO
     awk(1), ex(1), sed(1), sh(1)

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