home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 224_01 / grep.hlp < prev    next >
Encoding:
Text File  |  1987-01-06  |  4.1 KB  |  108 lines

  1. NAME
  2.      grep - search a file for a pattern
  3.  
  4. SYNTAX
  5.      grep [ option ] ...  [ expression ] [ file ] ...
  6.  
  7. DESCRIPTION
  8.      Grep searches the input files (standard input default) for lines 
  9.      matching a pattern.  Normally, each line found is copied to the 
  10.      standard output.  Grep patterns are regular expressions.  The 
  11.      following options are recognized.
  12.  
  13.      -v   All lines but those matching are printed.
  14.  
  15.      -c   Only a count of matching lines is printed.
  16.  
  17.      -l   The names of files with matching lines are listed
  18.           (once) separated by newlines.
  19.  
  20.      -n   Each line is preceded by its relative line number in
  21.           the file.
  22.  
  23.      -i   The case of letters is ignored in making comparisons.
  24.      -y   That is, upper and lower case are considered identical.
  25.  
  26.      -s   Silent mode.  Nothing is printed (except error messages).
  27.           This is useful for checking the error status (see DIAGNOSTICS).
  28.  
  29.      -h   Filename heading is omitted on each output line.  The default
  30.           case is that the file name is shown if there is more than
  31.           one input file. 
  32.  
  33.      -e expression
  34.           Same as a simple expression argument, but useful when
  35.           the expression begins with a -.
  36.  
  37.      -f file
  38.           The regular expression is taken from the file.
  39.  
  40.      Grep accepts regular expressions.  In the following description 
  41.      'character' excludes newline.  The regular expressions are as follows:
  42.  
  43.     ^          Matches the beginning of the line.
  44.  
  45.        $          Matches the end of the line.
  46.  
  47.       \          Matches the following character as follows:
  48.                         \b  =   Backspace
  49.                         \n  =   Linefeed
  50.                         \r  =   Carriage return
  51.                         \s  =   Space
  52.                         \t  =   tab
  53.             \nnn =  octal number for character
  54.                         \(any other character)  =   the character
  55.  
  56.     .          Matches any character.
  57.  
  58.       Character  Matches that character
  59.  
  60.     [ and ]    Encloses a string that specifies a character class.
  61.                 Any character in the brackets [] will be matched, as
  62.                well as a range, such as 'a-z', in the brackets [] will
  63.                be matched.  Also the compliment of the character class
  64.                    can be given with the string proceeded by the character ^.
  65.  
  66.      *          Matches the preceding expression zero or more times.
  67.  
  68.      : (colon)  OR logic operator between two expressions.
  69.  
  70.     &          AND logic operator between two expressions.
  71.  
  72.     !          NOT logic operator of an expression.
  73.  
  74.     ( ... )    Parentheses allow expressions to be groupd.
  75.  
  76.         The OR and AND operators have the same precedence and are lower than
  77.         the NOT operator.  The logic operators are parsed left to right.
  78.         If the expression is read from a file (-f option), then each line 
  79.         of input is considered to be separated by the OR logic operator.
  80.  
  81. EXAMPLES:
  82.     1.  Search for the word "main" in the files day1, day2, day3.
  83.  
  84.                               grep main day?
  85.  
  86.     2.  Search for the words "main" or "art" in the file day1.  Use the
  87.             option -n to print the line numbers too.  Also the case independent
  88.             option (-i) is choosen.
  89.  
  90.                          grep -ni 'main:art' day1
  91.  
  92.     3.  Search for any word beginning with "art" in the file day1.  Here
  93.             the notation [a-z]* means that any series of letters from a to z
  94.             will be matched.  So words like "art", "artfull", "artist", 
  95.             "artie" will be found.
  96.  
  97.                   grep '^art[a-z]*[\s\t\n]:[\s\t]art[a-z]*[\s\t\n]' day1
  98.  
  99. DIAGNOSTICS
  100.      Exit status is 0 if any matches are found, 1 if none, 2 for
  101.      syntax errors or inaccessible files.
  102.  
  103. RESTRICTIONS
  104.      Care should be taken when using the character * in the expression as 
  105.      it can be expanded for filenames, and the character $ as it can be 
  106.      expanded for environment parameters.  It is safest to enclose the entire
  107.      expression argument in single quotes '... '.  
  108.