home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNUGRE.ZIP / grep.man < prev    next >
Text File  |  1992-07-18  |  8KB  |  211 lines

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