home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Audio 4.94 - Over 11,000 Files
/
audio-11000.iso
/
msdos
/
sndbords
/
proaudio
/
fddmairq
/
grep.doc
< prev
next >
Wrap
Text File
|
1991-08-23
|
8KB
|
252 lines
GREP - Group Reduced Extremely Particularly
grep - a pattern matching utility
Syntax
grep [-options] [-.xx[N]] [-e] pattern [filename ...]
grep [-options] [-.xx[N]] -l listfile [filename ...]
grep [-options] [-.xx[N]] -l listfile -ofile -Ofile [filename ...]
Options
-f shark expressions disabled
-c case is significant
-v lines without pattern match
-S input is sorted, quit after all matches
-W write individual files of matches: pattern.grp
-p display matched pattern only
-s show progress of compare algorithm
-n display line numbers of matching lines,
reset numbers to zero across files
-N display line numbers of matching lines, no reset
-Q suppress normal output
-F suppress display of filenames on multiple files
-L display filenames only
-oname name= file for normal output
-Oname name= file for normal non-output
-dstr str= expression for end of line delimiter
-e next argument is pattern beginning with a dash
-l listfile patterns to match are contained in the
file specified by listfile
-m output multiple lines on multiple matches when
using patterns from listfile
-.xx xx = return value based on match count
nz (zr) = return TRUE (1) if not zero (zero) matches
nz return TRUE (1) if not zero matches
gt N if matches > N, return matches - N
lt N if matches < N, return N - matches
ge N if matches >=N, return matches - N, else -1
le N if matches <=N, return N - matches, else -1
Note: matches - N and N - matches, when greater than
254, lose their significance due to the DOS
maximum errorlevel of 255.
Note: the -m option affects the count for comparison
-Z reset all options to defaults (override environment
settings for use in batch files)
Operation
grep operates as a standard filter, reading the standard
input, unless filename arguments are present, and
writing to standard output.
Normal operation consists of a grep attempting to match
(using the "match" protocol described in match.doc)
a "pattern" on each of the newline-terminated lines
on its input, displaying each line as it matches.
Options allow grep to display lines that do not contain the
specified pattern, display the line numbers of
output lines, and even to accept a filename that
contains a list of patterns to match. Also, the
ability to disable the "shark expressions" feature
and operate strictly as a string "finder".
grep can separate a file into two files, lines that match
and lines that do not match, using the -o and -O
options. This option was used to process a customer
transaction list:
grep can output matching lines to individual files based on
the actual string matched using the -W option.
grep will generate a filename of "pattern.@@@" where
pattern is the actual matched string from the input
line. Lines with no matches are written to
"$nomatch.@@@", and patterns that are bad file names
are written to "$badname.@@@".
Particularly useful when processing large
amounts of data looking for key items.
This option will create a file named by
the item searched for, up to eight chars
in DOS, so that a list of keywords and
patterns can be processed on information
such as listings of stock quotations,
download listings, note files, and any
other groupings of information.
With the -S option, grep will terminate on the first non-match
after successfully matching any lines. When the input
is sorted, grep will not bother to look at lines after
the first non-match, allowing a little faster behavior
in certain situations.
The -dstr option will cause grep to convert the str argument
and use the result as the output line delimiter. str
can be a shark expression, or, if missing, no end of
line delimiter is output.
Default operation is as follows:
shark expressions are enabled
case is not significant
output consists of lines containing specified patterns
line numbers are not displayed
line numbers, when displayed, are reset across files
filenames preface each line for multiple input files
only one output line per match on listfile patterns
newline as the end of line delimiter
Note: if the pattern begins with a dash ("-") then the -e
option must be specified directly prior to the pattern
in order to prevent grep from interpreting the pattern
as an option string.
Note: the -s option may result in extremely voluminous output,
although it may be interesting to observe.
Return Value
grep normally returns zero, unless:
an invalid option is specified
no pattern was specified
a listfile is specified but unopenable
outputfiles were requested but not specified
or unopenable or unwritable
grep returns -1 if a return value was requested and
one of the above errors were encountered
grep return values for the logic operations are as follows:
nz if some matches, return TRUE (1)
zr if zero matches, return TRUE (1)
gt N if > N matches, return matches - N
lt N if < N matches, return N - matches
ge N if >=N matches, return matches - N,
else return ERROR (-1)
le N if <=N matches, return N - matches,
else return ERROR (-1)
if the -v option is specified:
nz if some non-matches, return TRUE (1)
zr if zero non-matches, return TRUE (1)
gt N if > N non-matches, return matches - N
lt N if < N non-matches, return N - matches
ge N if >=N non-matches, return matches - N,
else return ERROR (-1)
le N if <=N non-matches, return N - matches,
else return ERROR (-1)
Limitations
Does not allow for multiple expressions except from
a -l specified list file.
Processing of backslash-character combinations and
directory pathnames confuses the parser.
The Maximum Line Length of 512 can not be changed in this
version.
Comments
Please make any comments you have before you transfer this
to another.
The -c option, with the opposite meaning here as it does
on Unix, was implemented because a lot of assembly language
was being processed and the case was not significant. It
is a toggle value and the code can be patched.
The 512 character per line maximum... should it be variable?
Matches across lines: now that would be a handy feature.
Thanks
I am glad that a feature I was reluctant to incorporate,
but was insisted upon by Mr. Reich, the return to DOS
of errorvalues based on the number of matches, was included,
as I use this in situations others might disbelieve:
:chknet
grep -Q.nz "^device=*ramdrive.sys"
if errorlevel 1 goto haveram
set bat=c:\bat
goto quit
:haveram
echo d | xcopy c:\bat d:\bat
set bat=d:\bat
:quit
set path=%bat%;%bin%
Thanks also to Mr. Nicholson as he gave me cause to
access the environment.
And to Mr. Bernstein for having the need for writing
output files based on the pattern and for splitting the
output of matches and nonmatches to separate files:
grep -W -lsubject.lst list.txt
more *.@@@
grep -oisin.lst -Onotin.lst list.txt
more *.lst
Versions
See the executable for the version and syntax specifics.
Entering grep -- will cause the program to put the
syntax statement on standard output.
=======================================================================
grep - copyright SHARK 1991 - Programmer Bart Crane
All Rights Reserved - Distribution Encouraged
Software Provided As Is, No Warranty Express Or Implied
For More Information on SHARK, Upgrades, and other Utilities:
Mail:
SHARK
922 San Leandro Ave. Suite C
Mountain View, CA 94043
Telephone: (415) 969-3015
Fax: (415) 969-6600
Internet:
shark@parallax.com
Mediavision BBS:
(415) 770-0968 - Messages To: Bart Crane