home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / doc / grep.man < prev    next >
Text File  |  1993-06-13  |  9KB  |  265 lines

  1.  
  2.  
  3.  
  4. GREP(1)                                                   GREP(1)
  5.  
  6.  
  7. NAME
  8.        grep, egrep - print lines matching a regular expression
  9.  
  10. SYNOPSIS
  11.        grep  [ -CVbchilnsvwx ] [ -num ] [ -AB num ] [ [ -e ] expr
  12.        | -f file ] [ files ...  ]
  13.  
  14. DESCRIPTION
  15.        Grep searches the files listed in the arguments (or  stan-
  16.        dard  input if no files are given) for all lines that con-
  17.        tain a match for the given expr.  If any lines match, they
  18.        are printed.
  19.  
  20.        Also,  if  any  matches  were found, grep will exit with a
  21.        status of 0, but if no matches were  found  it  will  exit
  22.        with  a  status  of  1.  This is useful for building shell
  23.        scripts that use grep as a condition for, for example, the
  24.        if statement.
  25.  
  26.        When  invoked  as egrep the syntax of the expr is slightly
  27.        different; See below.
  28.  
  29. REGULAR EXPRESSIONS
  30.             (grep)    (egrep)(explanation)
  31.  
  32.             c         ca  single  (non-meta)  character   matches
  33.                                 itself.
  34.  
  35.             .         .matches  any  single character except new-
  36.                                 line.
  37.  
  38.             \?        ?postfix  operator;  preceeding   item   is
  39.                                 optional.
  40.  
  41.             *         *postfix  operator;  preceeding  item  0 or
  42.                                 more times.
  43.  
  44.             \+        +postfix operator;  preceeding  item  1  or
  45.                                 more times.
  46.  
  47.             \|        |infix operator; matches either argument.
  48.  
  49.             ^         ^matches  the empty string at the beginning
  50.                                 of a line.
  51.  
  52.             $         $matches the empty string at the end  of  a
  53.                                 line.
  54.  
  55.             \<        \<matches the empty string at the beginning
  56.                                 of a word.
  57.  
  58.             \>        \>matches the empty string at the end of  a
  59.                                 word.
  60.  
  61.  
  62.  
  63.  
  64. GNU Project              1988 December 13                       1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GREP(1)                                                   GREP(1)
  71.  
  72.  
  73.             [chars]   [chars]match  any  character  in  the given
  74.                                 class;  if  the  first  character
  75.                                 after [ is ^, match any character
  76.                                 not in the given class;  a  range
  77.                                 of characters may be specified by
  78.                                 first-last;   for   example,   \W
  79.                                 (below)   is  equivalent  to  the
  80.                                 class [^A-Za-z0-9]
  81.  
  82.             \( \)     ( )parentheses are used to override  opera-
  83.                                 tor precedence.
  84.  
  85.             \digit    \digit\n  matches  a  repeat  of  the  text
  86.                                 matched earlier in the regexp  by
  87.                                 the  subexpression inside the nth
  88.                                 opening parenthesis.
  89.  
  90.             \         \any special character may be preceded by a
  91.                                 backslash  to match it literally.
  92.  
  93.             (the following are for compatibility with GNU Emacs)
  94.  
  95.             \b        \bmatches the empty string at the edge of a
  96.                                 word.
  97.  
  98.             \B        \Bmatches  the  empty  string if not at the
  99.                                 edge of a word.
  100.  
  101.             \w        \wmatches word-constituent characters (let-
  102.                                 ters & digits).
  103.  
  104.             \W        \Wmatches  characters  that  are  not word-
  105.                                 constituent.
  106.  
  107.        Operator precedence is (highest to lowest) ?,  *,  and  +,
  108.        concatenation,  and  finally  |.  All other constructs are
  109.        syntactically identical to  normal  characters.   For  the
  110.        truly  interested,  the  file  dfa.c describes (and imple-
  111.        ments) the exact grammar understood by the parser.
  112.  
  113. OPTIONS
  114.        -A num print <num> lines of context after  every  matching
  115.               line
  116.  
  117.        -B num print  num  lines  of context before every matching
  118.               line
  119.  
  120.        -C     print 2 lines of context  on  each  side  of  every
  121.               match
  122.  
  123.        -num   print  num  lines  of context on each side of every
  124.               match
  125.  
  126.        -V     print the version number on the diagnostic output
  127.  
  128.  
  129.  
  130. GNU Project              1988 December 13                       2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. GREP(1)                                                   GREP(1)
  137.  
  138.  
  139.        -b     print every match preceded by its byte offset
  140.  
  141.        -c     print a total count of matching lines only
  142.  
  143.        -e expr
  144.               search for expr; useful if expr begins with -
  145.  
  146.        -f file
  147.               search for the expression contained in file
  148.  
  149.        -h     don't display filenames on matches
  150.  
  151.        -i     ignore case difference when comparing strings
  152.  
  153.        -l     list files containing matches only
  154.  
  155.        -n     print each match preceded by its line number
  156.  
  157.        -s     run silently producing no output except error  mes-
  158.               sages
  159.  
  160.        -v     print  only  lines  that contain no matches for the
  161.               <expr>
  162.  
  163.        -w     print only lines where the match is a complete word
  164.  
  165.        -x     print only lines where the match is a whole line
  166.  
  167. SEE ALSO
  168.        emacs(1), ed(1), sh(1), GNU Emacs Manual
  169.  
  170. INCOMPATIBILITIES
  171.        The following incompatibilities with UNIX grep exist:
  172.  
  173.             The  context-dependent  meaning of * is not quite the
  174.             same (grep only).
  175.  
  176.             -b prints a byte offset instead of a block offset.
  177.  
  178.             The {m,n} construct of System V grep  is  not  imple-
  179.             mented.
  180.  
  181.  
  182. BUGS
  183.        GNU e?grep has been thoroughly debugged and tested by sev-
  184.        eral people over a period of several months; we think it's
  185.        a reliable beast or we wouldn't distribute it.  If by some
  186.        fluke of the universe you discover a bug, send a  detailed
  187.        description (including options, regular expressions, and a
  188.        copy of an input  file  that  can  reproduce  it)  to  me,
  189.        mike@wheaties.ai.mit.edu.
  190.  
  191.        There  is  also  a newsgroup, gnu.utils.bug, for reporting
  192.        FSF utility programs' bugs and fixes; but before reporting
  193.  
  194.  
  195.  
  196. GNU Project              1988 December 13                       3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. GREP(1)                                                   GREP(1)
  203.  
  204.  
  205.        something  as  a bug, please try to be sure that it really
  206.        is a bug, not a misunderstanding or a deliberate  feature.
  207.        Also,  include  the  version number of the utility program
  208.        you are running in every bug  report  that  you  send  in.
  209.        Please  do not send anything but bug reports to this news-
  210.        group.
  211.  
  212.  
  213. AVAILABILITY
  214.        GNU grep is free; anyone may redistribute copies  of  grep
  215.        to anyone under the terms stated in the GNU General Public
  216.        License, a copy of which may be found in each copy of  GNU
  217.        Emacs.   See  also  the  comment  at  the beginning of the
  218.        source code file grep.c.
  219.  
  220.        Copies of GNU grep may sometimes be received packaged with
  221.        distributions of Unix systems, but it is never included in
  222.        the scope of any license  covering  those  systems.   Such
  223.        inclusion violates the terms on which distribution is per-
  224.        mitted.  In fact, the primary purpose of the General  Pub-
  225.        lic License is to prohibit anyone from attaching any other
  226.        restrictions to redistribution of any of the Free Software
  227.        Foundation programs.
  228.  
  229. AUTHORS
  230.        Mike  Haertel  wrote the deterministic regexp code and the
  231.        bulk of the program.
  232.  
  233.        James A. Woods is responsible for  the  hybridized  search
  234.        strategy  of  using Boyer-Moore-Gosper fixed-string search
  235.        as a filter before calling the general regexp matcher.
  236.  
  237.        Arthur David  Olson  contributed  code  that  finds  fixed
  238.        strings  for  the  aforementioned  BMG  search for a large
  239.        class of regexps.
  240.  
  241.        Richard Stallman wrote  the  backtracking  regexp  matcher
  242.        that  is  used  for  \digit backreferences, as well as the
  243.        getopt that is provided for 4.2BSD sites.  The  backtrack-
  244.        ing matcher was originally written for GNU Emacs.
  245.  
  246.        D.  A.  Gwyn wrote the C alloca emulation that is provided
  247.        so System V machines can run  this  program.   (Alloca  is
  248.        used  only  by  RMS'  backtracking  matcher, and then only
  249.        rarely, so there is no loss if your machine doesn't have a
  250.        "real" alloca.)
  251.  
  252.        Scott  Anderson  and Henry Spencer designed the regression
  253.        tests used in the "regress" script.
  254.  
  255.        Paul Placeway wrote the original version  of  this  manual
  256.        page.
  257.  
  258.  
  259.  
  260.  
  261.  
  262. GNU Project              1988 December 13                       4
  263.  
  264.  
  265.