home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1994 October
/
pslmonthlyvol2-10utilitiesoctober1994.iso
/
pastnews
/
fgrep.doc
< prev
next >
Wrap
Text File
|
1989-09-20
|
26KB
|
646 lines
FGREP 1.71
----------
"|" denotes changes 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, and arbitrary
sequences of bytes in other 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".
Syntax
------
FGREP's syntax is
| FGREP [-abBceflmMopsvwx01] target {@file}
Looks complicated, lots of switches, but the most common use is
very simple:
FGREP hello myfile.txt
This command would display all lines of MYFILE.TXT that contain
the string "hello".
Targets
-------
The target is what you're looking for in the file. There are
two ways to specify targets: as strings and as series of
hexadecimal bytes. The two can be combined in a single target
specification.
Strings are sequences of ASCII characters, like "hello".
Normally, you can just type in the string and forget it, but you
may have to "delimit" the string, i.e., bracket it by a pair of
matching non-alphanumeric characters (anything except - and $):
'string'
/string/
.string.
Choose a delimiter that does not appear in the string. This is
no good:
'you've made a mistake'
Delimiters are required for a string target if any of these four
conditions are met:
-- it is combined with hex byte sequences (more below)
-- 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 valid string targets:
mov
ax
"two words" (requires delimiter: 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.
REMEMBER that 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
Hex byte sequences are used for binary file searching when the
bytes to be searched for are non-displayable characters or make
no sense as strings (e.g., program code). They are specified as
pairs of hexadecimal bytes introduced by a leading '$':
$EF
$CD21 (CDh, 21h)
$CD$21 (identical; either format is OK)
$00FFFE00 (00h, FFh, FEh, 00h)
$CD 21 (ILLEGAL: no spaces permitted)
You can combine strings and hex sequences by using a '+':
"abc"+$E74A+"def"
Target wildcards
----------------
String targets (not hex targets) may contain one or mmore "?"
wildcards. The ? will match any single non-null character in
the file. E.g., "[?i]" will match "[si]", "[di]", etc., but not
"[i]". Wildcards are not permitted when hex byte sequences are
used.
If you want to search for the '?' character literally, use
'\?'. For example, the target
what\?
will search for the literal string "what?".
Specifying target files
-----------------------
You can list zero (see "Redirection"), one, or multiple files to
be searched. Files listed may include DOS's * and ? wildcards.
Paths may be specified. Examples:
myfile.txt
*.txt
*.*
this.c that.c other.c
*.c *.pas
C:\UTIL\*.* D:\SYS\*.*
E:\LIBRARY\*.D?C
| File lists
| ----------
| If the name of a file on the command line is prefixed with an
| '@' character (e.g., '@list.txt'), the file is assumed to be a
| text file containing the names of files to be searched. For
| example:
|
| fgrep hello @files.lst
|
| FGREP will assume that the file FILES.LST is a text file that
| contains the names of files to be searched. Each line of such a
| file should contain the name(s) of one or more files to be
| searched. Files in file lists are specified exactly as are
| files named on the command line, except that you can't use
| another '@' file list; that is, file lists can't be nested.
|
| Here is an example of a valid list file:
|
| this.c
| c:\c\*.c d:\c\*.c
| d:\misc\*.txt
|
| The name specified for the list file cannot contain wildcards;
| that is, this is illegal:
|
| fgrep hello @lists.* (WRONG)
|
| If you want to search for text in a file whose name begins with
| an '@', use a double '@'. For example,
|
| fgrep hello @@foo.txt
|
| will search for 'hello' in the file @FOO.TXT.
Redirection
-----------
If no file is listed, FGREP will take its input from the
standard input device, permitting redirection. For example:
DIR | fgrep pas
would display any lines from a directory listing that contain
the string "pas". Or,
DIR | fgrep "<dir>"
would list all subdirectories of the current directory.
This command:
arc p somefile foo.txt | FGREP somestring
would display all lines from the file FOO.TXT in the archive
file SOMEFILE that contain "somestring".
FGREP will terminate with an error if no file is listed and
standard input is not redirected. Otherwise, it would be
waiting for keyboard input to scan, possibly leading you to
believe that it had hung up.
Examples of use
---------------
Here are some examples of FGREP use:
1. List all lines of MYFILE.TXT containing "hello"
FGREP hello myfile.txt
2. List all lines of all *.C files in the current directory that
contain "include foo.c":
FGREP "include foo.c" *.c
3. List all lines from FILEA.EXT, FILEB.EXT, and FILEC.EXT that
contain the string "abcd" followed by any character:
FGREP abcd? filea.ext fileb.ext filec.ext
4. Display occurrences of the byte CDh followed by 21h (a DOS
call) in the program MYPROG.EXE:
FGREP $CD21 myprog.exe
5. Display occurrences of the string "abc" followed by a byte of
zeroes in all files in the C:\UTIL and D:\SYS:
FGREP 'abc' + $00 c:\util\*.* d:\sys\*.*
Output
------
FGREP's default screen output looks like this:
**File <filename>
[text of lines containing string]
**File <filename>
[text of lines containing string]
I