home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 154_01 / grep2.doc < prev    next >
Text File  |  1979-12-31  |  2KB  |  58 lines

  1.  
  2.  
  3.                      GREP
  4.  
  5.  
  6.     GREP searches files for lines matching a regular expression.
  7.  
  8.     Usage:
  9.         grep [-cfinv] pattern [file1 file2 ...]  (also a filter)
  10.  
  11.     Flags:
  12.         -c    only print count of matching lines
  13.         -f    file switch: Normally, file names are
  14.             only printed when more than one file
  15.             is requested.  This switch reverses
  16.             this option (it is printed if there
  17.             is one file only).
  18.         -i    ignore case in comparisons (GREP is
  19.             case-sensitive by default)
  20.         -n    each line is preceded by its line number
  21.         -v    only print non-matching lines
  22.  
  23.  
  24.     Wildcards and pathnames are allowed in file specifications, e.g.,
  25.  
  26.         grep  -fi  "[aeiou]+: "  b:\dir1\dir2\*.txt  c:prog?.*
  27.  
  28.     The regular expression should be quoted if it contains blanks.
  29.     Characters are matched by the following rules:
  30.  
  31.     x    any ordinary character not mentioned below
  32.     '\'    escapes (quotes) special characters seen below
  33.     '^'    beginning-of-line
  34.     '$'    end-of-line
  35.     '.'    any character except end-of-line
  36.     ':a'    alphabetic character
  37.     ':d'    digit
  38.     ':n'    alphanumeric
  39.     ': '    whitespace or other non-printable characters
  40.     '*'    zero or more occurrences of previous character
  41.     '+'    one or more occurrences of previous character
  42.     '-'    optionally match previous character (say what?)
  43.     '[]'    character classes:
  44.         --->    match any character in the enumerated set
  45.         (the example above matches a run of vowels followed by
  46.         whitespace).  Ranges are allowed, as in [a-z], which
  47.         would match a lower-case letter.  '^' as the first
  48.         character in a class means match anything but what
  49.         is in the class, so [^aeiou] would match a consonant.
  50.  
  51.     The source is not portable.  I build my own argv[] so I can
  52.     process quoted args with embedded spaces.  Also, Mark Williams'
  53.     built-in function exargs() expands wildcard filespecs for me
  54.     (you could easily do your own version of these techniques).
  55.  
  56.     Adapted from DECUS by Chuck Allison, (602) 742-2448, APR 85.
  57.     For non-commercial use only.
  58.