home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / grep-2.0-bin.lha / man / cat1 / grep.0
Encoding:
Text File  |  1993-12-07  |  10.7 KB  |  265 lines

  1.  
  2.  
  3.  
  4. GREP(1)                                                   GREP(1)
  5.  
  6.  
  7. NNAAMMEE
  8.        grep, egrep, fgrep - print lines matching a pattern
  9.  
  10. SSYYNNOOPPOOSSIISS
  11.        ggrreepp [ --[[AABB] ]_n_u_m ] [ --[CCEEFFGGVVBBcchhiillnnssvvwwxx] ] [ --ee ] _p_a_t_t_e_r_n
  12.        | --ff_f_i_l_e ] [ _f_i_l_e_s_._._.  ]
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.        GGrreepp searches the named input _f_i_l_e_s (or standard input  if
  16.        no files are named, or the file name -- is given) for lines
  17.        containing a match to the given _p_a_t_t_e_r_n.  By default, ggrreepp
  18.        prints the matching lines.
  19.  
  20.        There  are three major variants of ggrreepp, controlled by the
  21.        following options.
  22.        --GG     Interpret _p_a_t_t_e_r_n as  a  basic  regular  expression
  23.               (see below).  This is the default.
  24.        --EE     Interpret _p_a_t_t_e_r_n as an extended regular expression
  25.               (see below).
  26.        --FF     Interpret _p_a_t_t_e_r_n as a list of fixed strings, sepa-
  27.               rated by newlines, any of which is to be matched.
  28.        In  addition,  two  variant  programs  eeggrreepp and ffggrreepp are
  29.        available.  EEggrreepp  is  similiar  (but  not  identical)  to
  30.        ggrreepp --EE, and is compatible with the historical Unix eeggrreepp.
  31.        FFggrreepp is the same as ggrreepp --FF.
  32.  
  33.        All variants of ggrreepp understand the following options:
  34.        --_n_u_m   Matches will be printed with _n_u_m lines  of  leading
  35.               and  trailing  context.   However,  ggrreepp will never
  36.               print any given line more than once.
  37.        --AA _n_u_m Print _n_u_m lines of trailing context after  matching
  38.               lines.
  39.        --BB _n_u_m Print  _n_u_m lines of leading context before matching
  40.               lines.
  41.        --CC     Equivalent to --22.
  42.        --VV     Print the version number of ggrreepp to standard error.
  43.               This  version  number should be included in all bug
  44.               reports (see below).
  45.        --bb     Print the byte offset within the input file  before
  46.               each line of output.
  47.        --cc     Suppress  normal  output;  instead print a count of
  48.               matching lines for each input file.   With  the  --vv
  49.               option (see below), count non-matching lines.
  50.        --ee _p_a_t_t_e_r_n
  51.               Use  _p_a_t_t_e_r_n as the pattern; useful to protect pat-
  52.               terns beginning with --.
  53.        --ff _f_i_l_e
  54.               Obtain the pattern from _f_i_l_e.
  55.        --hh     Suppress the prefixing of filenames on output  when
  56.               multiple files are searched.
  57.        --ii     Ignore  case  distinctions  in both the _p_a_t_t_e_r_n and
  58.               the input files.
  59.        --LL     Suppress normal output; instead print the  name  of
  60.               each input file from which no output would normally
  61.  
  62.  
  63.  
  64. GNU Project             1992 September 10                       1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GREP(1)                                                   GREP(1)
  71.  
  72.  
  73.               have been printed.
  74.        --ll     Suppress normal output; instead print the  name  of
  75.               each  input  file  from which output would normally
  76.               have been printed.
  77.        --nn     Prefix each line of output  with  the  line  number
  78.               within its input file.
  79.        --qq     Quiet; suppress normal output.
  80.        --ss     Suppress   error   messages  about  nonexistent  or
  81.               unreadable files.
  82.        --vv     Invert  the  sense  of  matching,  to  select  non-
  83.               matching lines.
  84.        --ww     Select  only  those  lines  containing matches that
  85.               form whole words.  The test is  that  the  matching
  86.               substring  must  either  be at the beginning of the
  87.               line, or preceded by a non-word constituent charac-
  88.               ter.   Similarly,  it  must be either at the end of
  89.               the line or  followed  by  a  non-word  constituent
  90.               character.   Word-constituent  characters  are let-
  91.               ters, digits, and the underscore.
  92.        --xx     Select only those matches that  exactly  match  the
  93.               whole line.
  94.  
  95. RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS
  96.        A  regular expression is a pattern that describes a set of
  97.        strings.  Regular expressions are constructed  analagously
  98.        to  arithmetic  expressions, by using various operators to
  99.        combine smaller expressions.
  100.  
  101.        GGrreepp understands two different versions of regular expres-
  102.        sion  syntax:  ``basic''  and  ``extended.''  In GNU ggrreepp,
  103.        there is no difference in  available  functionality  using
  104.        either  syntax.   In  other implementations, basic regular
  105.        expressions are less powerful.  The following  description
  106.        applies  to  extended regular expressions; differences for
  107.        basic regular expressions are summarized afterwards.
  108.  
  109.        The fundamental building blocks are  the  regular  expres-
  110.        sions  that  match  a  single character.  Most characters,
  111.        including all letters and digits, are regular  expressions
  112.        that  match  themselves.   Any  metacharacter with special
  113.        meaning may be quoted by preceding it with a backslash.
  114.  
  115.        A list of characters enclosed by [[ and ]] matches any  sin-
  116.        gle  character in that list; if the first character of the
  117.        list is the caret ^^ then it matches any character  _n_o_t  in
  118.        the   list.    For   example,   the   regular   expression
  119.        [[00112233445566778899]] matches any single digit.  A range  of  ASCII
  120.        characters  may  be specified by giving the first and last
  121.        characters, separated by a hyphen.  Finally, certain named
  122.        classes  of  characters  are  predefined.  Their names are
  123.        self  explanatory,  and  they  are  [[::aallnnuumm::]],  [[::aallpphhaa::]],
  124.        [[::ccnnttrrll::]],  [[::ddiiggiitt::]],  [[::ggrraapphh::]],  [[::lloowweerr::]],  [[::pprriinntt::]],
  125.        [[::ppuunncctt::]],  [[::ssppaaccee::]],  [[::uuppppeerr::]],  and  [[::xxddiiggiitt::]]..   For
  126.        example,  [[[[::aallnnuumm::]]]] means [[00--99AA--ZZaa--zz]], except the latter
  127.  
  128.  
  129.  
  130. GNU Project             1992 September 10                       2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. GREP(1)                                                   GREP(1)
  137.  
  138.  
  139.        form is  dependent  upon  the  ASCII  character  encoding,
  140.        whereas  the  former is portable.  (Note that the brackets
  141.        in these class names are part of the symbolic  names,  and
  142.        must  be  included  in addition to the brackets delimiting
  143.        the bracket list.)  Most metacharacters lose their special
  144.        meaning  inside  lists.   To  include a literal ]] place it
  145.        first in the list.  Similarly,  to  include  a  literal  ^^
  146.        place  it  anywhere but first.  Finally, to include a lit-
  147.        eral -- place it last.
  148.  
  149.        The period ..  matches any single character.  The symbol \\ww
  150.        is  a  synonym  for  [[[[::aallnnuumm::]]]]  and  \\WW is a synonym for
  151.        [[^^[[::aallnnuumm]]]].
  152.  
  153.        The caret ^^ and the dollar sign $$ are metacharacters  that
  154.        respectively  match  the empty string at the beginning and
  155.        end of a line.  The symbols \\<< and \\>>  respectively  match
  156.        the  empty string at the beginning and end of a word.  The
  157.        symbol \\bb matches the empty string at the edge of a  word,
  158.        and  \\BB  matches the empty string provided it's _n_o_t at the
  159.        edge of a word.
  160.  
  161.        A regular expression matching a single  character  may  be
  162.        followed by one of several repetition operators:
  163.        ??      The  preceding item is optional and matched at most
  164.               once.
  165.        **      The preceding item will be  matched  zero  or  more
  166.               times.
  167.        ++      The  preceding  item  will  be  matched one or more
  168.               times.
  169.        {{_n}}    The preceding item is matched exactly _n times.
  170.        {{_n,,}}   The preceding item is matched _n or more times.
  171.        {{,,_m}}   The preceding item is optional and  is  matched  at
  172.               most _m times.
  173.        {{_n,,_m}}  The preceding item is matched at least _n times, but
  174.               not more than _m times.
  175.  
  176.        Two regular expressions may be concatenated; the resulting
  177.        regular  expression  matches any string formed by concate-
  178.        nating two substrings that respectively match the concate-
  179.        nated subexpressions.
  180.  
  181.        Two  regular expressions may be joined by the infix opera-
  182.        tor ||; the resulting regular expression matches any string
  183.        matching either subexpression.
  184.  
  185.        Repetition  takes  precedence over concatenation, which in
  186.        turn takes precedence over alternation.   A  whole  subex-
  187.        pression  may be enclosed in parentheses to override these
  188.        precedence rules.
  189.  
  190.        The backreference \\_n, where _n is a single  digit,  matches
  191.        the  substring previously matched by the _nth parenthesized
  192.        subexpression of the regular expression.
  193.  
  194.  
  195.  
  196. GNU Project             1992 September 10                       3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. GREP(1)                                                   GREP(1)
  203.  
  204.  
  205.        In basic regular expressions the metacharacters ??,  ++,  {{,
  206.        ||,  ((,  and  )) lose their special meaning; instead use the
  207.        backslashed versions \\??, \\++, \\{{, \\||, \\((, and \\)).
  208.  
  209.        In eeggrreepp the metacharacter {{ loses  its  special  meaning;
  210.        instead use \\{{.
  211.  
  212. DDIIAAGGNNOOSSTTIICCSS
  213.        Normally, exit status is 0 if matches were found, and 1 if
  214.        no matches were found.  (The --vv option inverts  the  sense
  215.        of  the exit status.)  Exit status is 2 if there were syn-
  216.        tax errors in the pattern, inaccessible  input  files,  or
  217.        other system errors.
  218.  
  219. BBUUGGSS
  220.        Email  bug  reports  to bbuugg--ggnnuu--uuttiillss@@pprreepp..aaii..mmiitt..eedduu.  Be
  221.        sure to include the word ``grep'' somewhere in the  ``Sub-
  222.        ject:'' field.
  223.  
  224.        Large  repetition  counts in the {{_m,,_n}} construct may cause
  225.        grep to use lots of memory.  In  addition,  certain  other
  226.        obscure  regular  expressions require exponential time and
  227.        space, and may cause ggrreepp to run out of memory.
  228.  
  229.        Backreferences are very slow, and may require  exponential
  230.        time.
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. GNU Project             1992 September 10                       4
  263.  
  264.  
  265.