GREP is a filter that searches input files, or the standard input, for lines that contain matches for one or more patterns called regular expressions and displays those matching lines. GREP can also search binary files and display records or buffers that contain matches.
This document is the complete revision history, starting with the most recent changes. To use GREP, please see the user guide and the reference manual.
Note: This is a pre-release of 7.0. Registered users are being polled for desired features, and their responses will help determine any additional changes for 7.0. If you would like to participate in the poll, send e-mail to the author.
Program changes:
Binary file modes have been completely overhauled. The old
/R
toggle has been replaced by a mode selection
via the /R2
option
for record-oriented binary or the
/R3
option
for free-format binary. This solves a known but serious problem
with the old binary mode, where a match would be missed if it
crossed a block boundary.
The new /R-1
or
/R-2
option lets you tell GREP to figure out on its
own whether each input file is text or binary. (/R-1
and
/R-2
are available only with the registered version.)
You can now specify different widths for binary blocks and text
lines with the /W
option.
The /W
option minimum value, formerly 10 characters, is
now 2.
(GREP32 only) The new /M
option allows correct
case-blind matching and
character classes with
non-English letters and other 8-bit characters.
(A test file is included.)
Binary output now displays the hex value
<nn>
for every non-printing character,
according to the current character set
(/M
option).
A new demo file, DEMO.BAT, is included.
The new /J
option
tells GREP to display from each line only the portion that matched the
search string, basic regex, or extended regex. In release 6.0, this
was added for extended regexes only, and you specified the /E3
option. /E3
is still allowed, but is equivalent to /E2 /J
.
In record-oriented binary files
(/R2
option),
the ^
anchor at the start and $
anchor at the end of a basic regex now mean the start and end of
block, for better consistency with extended regexes.
GREP is now about 5% faster on text files, and NUL (ASCII 0) will no longer cause the rest of a line to be ignored.
With the /L
option,
GREP now stops reading a file as soon as it finds a match, unless the
/V
option is also set.
Debug output now includes additional information:
/W
option
Bug fix: Release 6.0 began diagnosing
wildcard filespecs that produce no files at all, even when the
/S
(subdirectory) option is set. Unfortunately, the code
to do that broke the previous code that diagnosed missing single
files. The code to check the various cases is now collected in one
place, and diagnosis should be correct and complete.
Bug fix: The numeric values of the
/Q
option were added to
debug output and the help message, where they should have been for
release 6.0.
Documentation changes (in addition to those driven by the above program changes):
The user guide had grown more and more unwieldy. All the details of options and regexes are now split off into a separate reference manual, which is included in the download file but not published on the Web.
A table of options with one-line descriptions and a summary of regexes were added to the user guide; both are hyperlinked to sections in the reference manual. This may make it easier to find the feature you need.
Information on greedy and ungreedy quantifiers was added to the reference manual and to the help message.
The groups of options in the reference manual and the help message were rearranged to input, pattern-matching, output, and general.
The writeups of several options in the help message were expanded.
Note: There were beta test releases numbered 5.95, 5.97, and 5.98. For users who participated in the beta test, a number in parentheses indicates the release where a particular change was made.
(5.95) The big news is the addition of extended regular expressions. GREP can now handle constructs like alternatives |, optionals ?, general quantifiers {...}, subexpressions (...), and more. With extended regexes, you can choose whether GREP reports matching lines as usual, or just the portion of each line that matches the extended regex.
Other program changes with this release:
(5.95) You can now bypass regular expressions entirely and just search for literal text.
(5.97) You can now turn the Special Rules for the Command Line on and off.
(5.98) You now have finer-grained control over warning messages
with numeric levels for the /Q
option.
(5.97) GREP now displays a
warning message for any file spec that matches no files, even if the
/S
option (search
subdirectories) is on.
(5.97) You can now put a plus sign
after an option to turn it on (as opposed to toggling it). Example:
repeated /N
will flip the option between on and off, but
/N+
turns on the option regardless of any previous
settings.
(5.98) Character types and assertions were added to the help message.
(5.95) When you put a regex on the command line, you may need to
enclose it in quotes, and if you do then GREP strips them (as past
releases did). But, in agreement with the user guide, it no longer
does that with regexes entered in a file or at the keyboard
(/F
option).
(5.95) Two bugs in parsing oddly constructed character classes
were fixed.
(1) If you had a regex like []abc]
, GREP
wrongly took the first square bracket as ending the class. GREP now
correctly treats a ] at the beginning of a character class as an
ordinary character.
(2) A minus sign at the end of a class, like [abc-]
,
is now treated correctly as a normal character.
(5.95) The user guide told you that when your regex begins with a - or / character, you should prefix it with a \ to keep it from being taken as an option. GREP was considering that leading \ as part of the regex; it doesn't any more.
(5.98) If you specify named input files and also redirected input (<file), GREP has always ignored the redirected input. A warning message now appears in this case.
(5.97) The /Z
option used to reset all options except /F
; it now
resets all options as documented.
User guide changes:
(5.95) The section on regular expressions was pretty much rewritten, rather than try to shoehorn in all the stuff for extended regexes. (Only about 80% of the syntax of extended regular expressions was added to the user guide, though all is supported in the program. For a complete description, the relevant parts of the PCRE man page are also included.)
(5.95) A section on troubleshooting was added.
(5.97) The section on the environment
variable now makes clear that the /Z
option resets all
options including /D
and /F
.
(5.97) The section on Special Rules for the Command Line was reorganized to make it clearer when you do and don't need the rules, and information was added on the new ability to turn them on and off.
This is a repackaging for Simtel; there are no significant functional changes.
If you specified current directory on another disk, such as "d:*.htm", GREP was taking that as root directory, "d:\*.htm". Apparently no one but the program author ever does such a thing!
Unfortunately, a bug was introduced in release 5.3: under certain circumstances, GREP got confused about whether it was working from standard input or input files. This release corrects that bug, with my apologies to everyone who downloaded the buggy 5.3.
New features:
/Y
option lets you search
for lines that contain multiple regexes in any order.
/D
option now allows the pseudo
filename "-", for debugging display on standard output.
ERRORLEVEL
instead of 252.
more
to paginate the message.
/R
option to read and
display files in binary mode
/W
option to set the line width
(formerly fixed at 255 characters), and warn the user if longer lines
were found
/Z
option to reset all
options
z-a
; previously they were silently treated like the three
characters "z", "-", "a"
grep
with no options or regular expression; instead,
suggest using grep /? |more
d:*
, the drive was ignored
/S
option for searching subdirectories (4.4)
/A
option
for searching hidden and system files (4.4)
[\244-\246\248-\255]
,
with adjacent escaped 8-bit character ranges, were not expanded
correctly (4.5)
\e
in regular
expressions was expanded to
Control-W (octal 27) instead of Escape (decimal 27) (4.5)
/D
and /I
options,
and add quite a few internal hyperlinks (4.5)
/F-
option
/I
, character classes entered in
lower case were expanded incorrectly
/U
option (UNIX-style output) and the
/Q
option (quiet). Distinguish between option errors in
the environment variable and on the command line
/P
); diagnose conflicts
only after the last option has been scanned
/D
(debug), which
is no longer a toggle
/P
(show context lines) to 2,2 if user specifies
/P
without numbers
/F
option (multiple regular expressions in a
file)
/P
option, remove the < > widgets
around the line numbers of the context lines, so that the lines
that actually match are more easily seen
/L
option
[]
as a user error, not an internal error
/S
option (search subdirectories), because
GREP's code now uses the C run-time library to interpret file specs on
the command line
[...]
in regular expressions, the
backslash was swallowing an extra character
/0
and /1
options to control
exit status
/D
now shows the number of matches in each
file, total matches, and exit status
\0x9A
, \045
,
and \211
in the regular expression
/P
option (show context lines around the
actual matches)
/D
is on the command line
+
in regular expressions (match one or more
occurrences)
/S
option (search subdirectories)
/B
option: now the default
is to show only the names of matching files
/C
(count matches) is
specified and /B
is not
[...]
character classes containing the range
character -
weren't always expanded correctly
/B
option (show only the names of files that
contain matches)
/D
option show the input pattern as well as
the decoded version
[...]
weren't working with
the /I
option
/I
option (ignore case)
\e
(escape) and
\q
(equal sign)