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 >
Wrap
Text File
|
1979-12-31
|
2KB
|
58 lines
GREP
GREP searches files for lines matching a regular expression.
Usage:
grep [-cfinv] pattern [file1 file2 ...] (also a filter)
Flags:
-c only print count of matching lines
-f file switch: Normally, file names are
only printed when more than one file
is requested. This switch reverses
this option (it is printed if there
is one file only).
-i ignore case in comparisons (GREP is
case-sensitive by default)
-n each line is preceded by its line number
-v only print non-matching lines
Wildcards and pathnames are allowed in file specifications, e.g.,
grep -fi "[aeiou]+: " b:\dir1\dir2\*.txt c:prog?.*
The regular expression should be quoted if it contains blanks.
Characters are matched by the following rules:
x any ordinary character not mentioned below
'\' escapes (quotes) special characters seen below
'^' beginning-of-line
'$' end-of-line
'.' any character except end-of-line
':a' alphabetic character
':d' digit
':n' alphanumeric
': ' whitespace or other non-printable characters
'*' zero or more occurrences of previous character
'+' one or more occurrences of previous character
'-' optionally match previous character (say what?)
'[]' character classes:
---> match any character in the enumerated set
(the example above matches a run of vowels followed by
whitespace). Ranges are allowed, as in [a-z], which
would match a lower-case letter. '^' as the first
character in a class means match anything but what
is in the class, so [^aeiou] would match a consonant.
The source is not portable. I build my own argv[] so I can
process quoted args with embedded spaces. Also, Mark Williams'
built-in function exargs() expands wildcard filespecs for me
(you could easily do your own version of these techniques).
Adapted from DECUS by Chuck Allison, (602) 742-2448, APR 85.
For non-commercial use only.