


GREP(1)                                                   GREP(1)


NNAAMMEE
       grep, egrep - print lines matching a regular expression

SSYYNNOOPPSSIISS
       ggrreepp  [ --CCVVbbcchhiillnnssvvwwxx ] [ --_n_u_m ] [ --AABB _n_u_m ] [ [ --ee ] _e_x_p_r
       | --ff _f_i_l_e ] [ _f_i_l_e_s _._._.  ]

DDEESSCCRRIIPPTTIIOONN
       _G_r_e_p searches the files listed in the arguments (or  stan-
       dard  input if no files are given) for all lines that con-
       tain a match for the given _e_x_p_r.  If any lines match, they
       are printed.

       Also,  if any matches were found, _g_r_e_p exits with a status
       of 0, but if no matches were found it exits with a  status
       of  1.  This is useful for building shell scripts that use
       _g_r_e_p as a condition for, for example, the _i_f statement.

       When invoked as _e_g_r_e_p the syntax of the _e_x_p_r  is  slightly
       different; See below.

RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS
            (grep)    (egrep)   (explanation)

            _c         _c         a   single  (non-meta)  character
                                matches itself.

            .         .         matches  any   single   character
                                except newline.

            \?        ?         postfix operator; preceeding item
                                is optional.

            *         *         postfix operator; preceeding item
                                0 or more times.

            \+        +         postfix operator; preceeding item
                                1 or more times.

            \|        |         infix  operator;  matches  either
                                argument.

            ^         ^         matches  the  empty string at the
                                beginning of a line.

            $         $         matches the empty string  at  the
                                end of a line.

            \<        \<        matches  the  empty string at the
                                beginning of a word.

            \>        \>        matches the empty string  at  the
                                end of a word.




GNU Project              1988 December 13                       1





GREP(1)                                                   GREP(1)


            [_c_h_a_r_s]   [_c_h_a_r_s]   match  any character in the given
                                class;  if  the  first  character
                                after [ is ^, match any character
                                not in the given class;  a  range
                                of characters may be specified by
                                _f_i_r_s_t_-_l_a_s_t;   for   example,   \W
                                (below)   is  equivalent  to  the
                                class [^A-Za-z0-9]

            \( \)     ( )       parentheses are used to  override
                                operator precedence.

            \_d_i_g_i_t    \_d_i_g_i_t    \_n  matches  a repeat of the text
                                matched earlier in the regexp  by
                                the  subexpression inside the nth
                                opening parenthesis.

            \         \         any special character may be pre-
                                ceded  by a backslash to match it
                                literally.

            (the following are for compatibility with GNU Emacs)

            \b        \b        matches the empty string  at  the
                                edge of a word.

            \B        \B        matches  the  empty string if not
                                at the edge of a word.

            \w        \w        matches word-constituent  charac-
                                ters (letters & digits).

            \W        \W        matches  characters  that are not
                                word-constituent.

       Operator precedence is (highest to lowest) ?,  *,  and  +,
       concatenation,  and  finally  |.  All other constructs are
       syntactically identical to  normal  characters.   For  the
       truly  interested,  the  file  dfa.c describes (and imple-
       ments) the exact grammar understood by the parser.

OOPPTTIIOONNSS
       --AA _n_u_m print <num> lines of context after  every  matching
              line

       --BB _n_u_m print  _n_u_m  lines  of context before every matching
              line

       --CC     print 2 lines of context  on  each  side  of  every
              match

       --_n_u_m   print  _n_u_m  lines  of context on each side of every
              match




GNU Project              1988 December 13                       2





GREP(1)                                                   GREP(1)


       --VV     print the version number on the diagnostic output

       --bb     print every match preceded by its byte offset

       --cc     print a total count of matching lines only

       --ee _e_x_p_r
              search for _e_x_p_r; useful if _e_x_p_r begins with -

       --ff _f_i_l_e
              search for the expression contained in _f_i_l_e

       --hh     don't display filenames on matches

       --ii     ignore case difference when comparing strings

       --ll     list files containing matches only

       --nn     print each match preceded by its line number

       --ss     run silently producing no output except error  mes-
              sages

       --vv     print  only  lines  that contain no matches for the
              <expr>

       --ww     print only lines where the match is a complete word

       --xx     print only lines where the match is a whole line

SSEEEE AALLSSOO
       emacs(1), ed(1), sh(1), _G_N_U _E_m_a_c_s _M_a_n_u_a_l

IINNCCOOMMPPAATTIIBBIILLIITTIIEESS
       The following incompatibilities with UNIX _g_r_e_p exist:

            The  context-dependent  meaning of * is not quite the
            same (grep only).

            --bb prints a byte offset instead of a block offset.

            The {_m_,_n} construct of System V grep  is  not  imple-
            mented.


BBUUGGSS
       GNU  _e_?_g_r_e_p has been thoroughly debugged and tested over a
       period of several years; we think it's a reliable beast or
       we  wouldn't  distribute it.  If by some fluke of the uni-
       verse you discover a  bug,  send  a  detailed  description
       (including  options, regular expressions, and a copy of an
       input file that can reproduce it) to mike@ai.mit.edu.





GNU Project              1988 December 13                       3





GREP(1)                                                   GREP(1)


AAUUTTHHOORRSS
       Mike Haertel wrote the deterministic regexp code  and  the
       bulk of the program.

       James  A.  Woods  is responsible for the hybridized search
       strategy of using Boyer-Moore-Gosper  fixed-string  search
       as a filter before calling the general regexp matcher.

       Arthur  David  Olson  contributed  code  that  finds fixed
       strings for the aforementioned  BMG  search  for  a  large
       class of regexps.

       Richard  Stallman  wrote  the  backtracking regexp matcher
       that is used for \_d_i_g_i_t backreferences, as well as the GNU
       getopt.   The  backtracking matcher was originally written
       for GNU Emacs.

       D. A. Gwyn wrote the C alloca emulation that  is  provided
       so  System  V  machines  can run this program.  (Alloca is
       used only by RMS'  backtracking  matcher,  and  then  only
       rarely, so there is no loss if your machine doesn't have a
       "real" alloca.)

       Scott Anderson and Henry Spencer designed  the  regression
       tests used in the "regress" script.

       Paul  Placeway  wrote  the original version of this manual
       page.





























GNU Project              1988 December 13                       4


