man(1) Manual page archive


     GRE(1)                                                     GRE(1)

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

     SYNOPSIS
          gre [ option ... ] pattern [ file ... ]

          grep [ option ... ] pattern [ file ... ]

          egrep [ option ... ] pattern [ file ... ]

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

     DESCRIPTION
          Gre searches the input files (standard input default) for
          lines (with newlines excluded) that match the pattern, a
          regular expression as defined in re(3). A file name of - is
          interpreted as standard input.  Normally, each line matching
          the pattern is `selected', and each selected line is copied
          to the standard output.  The options are

          -1   Print only the first selected line of each file argu-
               ment.
          -b   Mark each printed line with its byte position in its
               file.  This is sometimes useful in locating patterns in
               non-text files.
          -c   Print only a count of matching lines.
          -e pattern
               Same as a simple pattern argument, but useful when
               pattern begins with a -.
          -E   Simulate egrep.
          -f file
               Read the pattern from file; there is no pattern argu-
               ment
          -F   Simulate fgrep.
          -G   Simulate grep.
          -h   Do not print filename tags (headers) with output lines.
          -i   Ignore alphabetic case distinctions.
          -l   Print the names of files with selected lines; don't
               print the lines.
          -L   Print the names of files with no selected lines; the
               converse of -l.
          -n   Mark each printed line with its line number counted in
               its file.
          -s   Produce no output, but return status.
          -v   Reverse: print lines that do not match the pattern.
          -x   Exact match: The pattern is ^(pattern)$.  The implicit
               parentheses count in back references.

          Output lines are tagged by filename when there is more than
          one input file.  (To force this tagging, include /dev/null

     GRE(1)                                                     GRE(1)

          as a filename argument.)  If the output line exceeds some
          internal limit, a warning is given and a small block of text
          surrounding the match is printed.

          Care should be taken when using the shell metacharacters
          $*[^|()\ and newline in pattern; it is safest to enclose the
          entire expression in single quotes '...'.

          Gre supplants three classic programs, which are still avail-
          able:

          Grep handles only ed(1)-like regular expressions.  It uses
          `\(\)' instead of `()'.

          Egrep handles the same patterns as gre except for back-
          referencing with \1, \2, ...

          Fgrep handles no operators except newline (alternation).

     SEE ALSO
          re(3), awk(1), sed(1), sam(9.1), strings(1)

     DIAGNOSTICS
          Exit status is 0 if any lines are selected, 1 if none, 2 for
          syntax errors, inaccessible files (even if matches were
          found).  Warnings will be given for input lines that exceed
          a (generous) internal limit.

     BUGS
          Grep, egrep, and fgrep do not support some options and print
          (approximate) block numbers rather than byte numbers for
          option -b.
          Egrep may fail on input containing characters greater than
          0176.