home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
packet
/
bis_v20.arc
/
FGREP.DOC
< prev
next >
Wrap
Text File
|
1988-06-15
|
14KB
|
350 lines
fgrep 1.62
----------
"|" denotes items that are new/changed in the recent versions.
Purpose
-------
Fgrep (Fast GREP) is a small utility that can be used to find
strings of characters in ASCII text files. String search
capabilities are not extensive (no regular expressions), but
fgrep is small and very, very fast. Fgrep is intended to
replace DOS's FIND filter with something faster and more
flexible.
UNIX people: we fully realize that this isn't the grep or fgrep
with which you are familiar. We know that the RE in GREP means
"regular expressions" and we know that we don't support regular
expressions. However, the name serves to point people in the
right direction. Please don't write to tell us that this "isn't
really grep".
Using fgrep
-----------
Fgrep's syntax is
fgrep [-aceflmopsvwx01] target {file}
The -switches are discussed below.
The target is the string of characters for which you are
searching. It may need to be bracketed by a pair of
non-alphanumeric delimiters. The target should be delimited if:
-- it contains spaces or tabs
-- it begins with a non-alphanumeric character
-- it contains the DOS redirection characters < > |.
In the last case, the string MUST be delimited by double quotes
("), otherwise DOS will interpret it as redirection.
Examples of targets:
mov
ax
/mov ax/ (contains a space)
'/7' (begins with non-alphanumeric)
"f->x" (contains ">", must use double quotes)
It is always OK to delimit a string, even if delimiters are
unnecessary.
If the target contains DOS redirection characters (<, >, or |),
it MUST be delimited with double quotes ("") or DOS will try to
perform unwanted redirection. For example:
fgrep "a<=b" myfile.pas
The string may include one or more "?" wildcards. The ? will
match any single non-null character in the file. E.g., "[?i]"
will match "[si]", "[di]", etc., but not "[i]".
The list of files may include wild cards. Here are some
examples of fgrep use:
fgrep -c "include foo.c" *.c
fgrep abcd? filea.ext fileb.ext filec.ext
fgrep -1f 'call fido' a:\masm\*.asm b:*.asm
fgrep ax *.asm
If no file is specified, input will be taken from standard
input, allowing redirection and piping. For example:
arc p somefile foo.txt | fgrep somestring
will display occurrences of "somestring" in the file archived as
foo.txt in somefile.arc.
Output
------
Fgrep's default screen output looks like this:
**File <filename>
[text of lines containing string]
**File <filename>
[text of lines containing string]
| If the "Microsoft" (-M) switch is used, the output is in this
| format:
|
| FILE.EXT(linenum): text
|
| This format is the standard format used by Microsoft (R)
| language products and by its MEGREP.
All useful output is sent to the standard output device, so it
may be piped to other programs or redirected to file:
fgrep target filea | yourprog
fgrep target filea > test.txt
Error messages and the program logo will appear always appear on
the console device, and will never appear in redirected or piped
output.
Fgrep always returns an errorlevel to the operating system. It
will be one of:
0: String not found in any file
1: String found in at least one file
255: Error (file read error or bad parameter)
Switches
--------
-A is ANSI mode. If you have ANSI.SYS (or equivalent)
installed, escape characters (ASCII 27) in displayed text
lines can cause odd results. If you use the -A switch,
FGREP will substitute an upside-down question mark (¿) for
ESC, possibly resulting in cleaner displays. You'll only
need this switch if you have ANSI installed and there are ESC
characters in the files you're scanning.
-C makes the search case sensitive ("String" will not match
"string" or "STRING"). Normally, fgrep ignores case.
-E specifies that ONLY an errorlevel is to be returned.
There will be no display at all. This is equivalent to the
combination -s0.
-F causes the "**File" header lines to be displayed only for
those files that contain the search string.
-L adds line numbers to fgrep's output.
-M specifies Microsoft (R) output format. See "Output" above.
-O specifies a maximum output width. It should be followed by a
decimal number from 1 to 255. For example, -O40 causes fgrep
to truncate all output to a maximum of 40 characters per
line. Do not confuse the "O" (Output) switch with the "0"
(zero text) switch.
-P pauses on full screen of output
-S suppresses the "**File" header lines in the output.
-V provides a reVerse or negative search. That is, all lines
that do NOT contain the specified string are displayed. This
provides a handy way to get rid of lines containing specified
text. Suppose, for example, that you have a file containing
a list of file names, and you are interested in all files
EXCEPT those that contain a '$' in the name (perhaps they are
temporary files):
fgrep -v "$" filename
-W switch indicates that white space (blanks and tabs) is not
significant. White space in both the search string and the
input file will be ignored. If -w is specified, the wildcard
character (?) will match any nonblank character.
-X Do not display the logo/copyright.
-0 ("0" text lines) suppresses the display of lines of text
containing the specified string. Fgrep will skip immediately
to the next file when the string is found. Do not confuse
this with the "O" (Output width) switch.
-1 ("1" text line) specifies that only the first line containing
containing the specified string in each file will be
displayed. Fgrep will then skip immediately to the next
file.
"Fast" search algorithm
-----------------------
Beginning with version 1.55, a new and faster technique is used
for some searches. This algorithm will NOT be used if:
| - line numbers or Microsoft (R) format used (-L or -M)
- the search is reVerse (-V)
- the search is whitespace insensitive (-W)
- the target string contains wildcards ("?")
For other searches, the new technique is typically 20-40% faster
than the old, although we've seen 70% improvements in some
cases. One tester reported that fgrep located a string in the
last line of a 440K file in 0.97 seconds (IBM AT).
The technique has its roots in searching for unusual (less
frequently used) characters, so it will make more of a
difference searching for "squeeze" (q is a little-used letter)
than it will searching for "eat".
When fgrep can use the fast technique, input lines are not
limited to 500 characters (as they have been with past
versions).
Notes
-----
1. The -f and -s switches are mutually exclusive. If both are
specified, the last one will be effective.
2. If you specify the -e switch, fgrep will stop processing as
soon as a nonzero errorlevel is determined. The -e switch is
really designed to enable other programs to determine whether or
not a specific file contains a specific string in as little time
as possible. For example, here's an algorithm that will quickly
'touch' all files that do NOT contain a specified string:
for file in (*.*) do
fgrep -e string file
if errorlevel < 1 then touch file
end
3. The -s switch is automatically set when input is taken from
standard input.
4. Fgrep optimizes the combination -s0 (suppress headers, no
text) to a -e.
5. If you just want to know which files contain a string, use -0;
it saves time because the rest of the file (after the first hit)
is skipped. The combination -0f is particularly efficient
for this as it will simply display a list of files that contain
the string.
| 6. If any of the -V, -W, -L, or -M switches are used, or if the
target contains wildcards, input lines are limited to a maximum
| length of 500 characters (if you use a -w search, spaces don't
count). Fgrep expects standard text files; binary files will
yield weird results. Word processor files may or may not work,
depending on how they are formatted. Lines can be terminated by
any of CR, LF, or CR+LF.
7. If output is redirected to disk, make sure there is enough
space available. The program does not check.
Version 1.62
------------
Added -M switch.
Increased max length of lines ("slow" search) from 256 to 500.
Version 1.61
------------
Fixed a problem with pausing on > 255 hits (-P not specified).
Version 1.60
------------
Added -P switch.
Fixed a problem with tab characters and -O switch.
Version 1.59
------------
Added -O switch.
Altered -L operations to allow for line numbers > 65535. Line
numbers now right justified in a 6-character field.
Version 1.58
------------
Fixed two problems that were causing endless loops in 1.55-1.57.
Added -A switch.
Version 1.57
------------
Added -X switch.
Versions 1.55/1.56
-----------------
"Fast" search algorithm added (thanks to Dave Angel for the
idea and the shove).
Fixed problems with redirected input.
Forced -v (reVerse) search to show blank lines.
Versions 1.50/1.51
------------------
These versions contain no new features but are significantly
faster than earlier versions. Standard (case-insensitive)
searches run about 40% faster than 1.45 (which was 25-30%
faster than 1.40). "Literal" searches (case-sensitive and
spacing-sensitive) are highly optimized and may be as much as
70% faster than 1.45.
Version 1.45
------------
We found a few areas that could be made more efficient. This
version can be as much as 25-30% faster than version 1.40.
The -L (line numbers) option was added, and improvements made to
parameter parsing such that delimiters are not always necessary.
Copyright/License/Warranty
--------------------------
This document and the program file FGREP.COM ("the software")
are copyrighted by the author. The copyright owner hereby
licenses you to: use the software; make as many copies of the
program and documentation as you wish; give such copies to
anyone; and distribute the software and documentation via
electronic means. There is no charge for any of the above.
However, you are specifically prohibited from charging, or
requesting donations, for any such copies, however made; and
from distributing the software and/or documentation with
commercial products without prior permission. An exception is
granted to not-for-profit user's groups, which are authorized to
charge a small fee (not to exceed $7) for materials, handling,
postage, and general overhead. NO FOR-PROFIT ORGANIZATION IS
AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
ANY OTHER SUCH FEE FOR THE DISTRIBUTION. NO FOR-PROFIT
ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
FOR WHICH MONEY IS CHARGED. PERIOD.
No copy of the software may be distributed or given away without
this document; and this notice must not be removed.
There is no warranty of any kind, and the copyright owner is not
liable for damages of any kind. By using this free software,
you agree to this.
The software and documentation are:
Copyright (C) 1985-1988 by
The Cove Software Group
Christopher J. Dunford
P.O. Box 1072
Columbia, Maryland 21044
(301) 992-9371
CompuServe 76703,2002 [IBMNET]