Free Software for DOS
Text Utilities – 1
Search / Search & Replace

9 Dec 2005

Global Menu:
Go back to Front Page Menus

Go to top of Text Utils – 2
Go to top of Text Utils – 3
Go to top of Text Utils – 4
Go to top of Text Utils – 5

This page:

sed – stream editor


grep – global regular expression print


Page 2:




Page 3:





Page 4:




Page 5:







Notes: Penta Text Tools can operate on one machine or over a network. ALTERTexRepGSAR are good choices for quick and dirty multiple file s/r. MiniTrue can run interactively, displaying context of matches in an internal viewer, prompt for replace, and includes basic and extended regular expression support. CHANGE can perform s/r with respect to presence of other strings on a line. sed is a power user's tool that supports regular expressions. Also see: awkPerl.

Penta Text Tools — Search, view, process strings in any text file.


[added 2000-09-10, updated 2004-08-20]

Based on Unix tools, these run on any DOS 2.0+ or emulator.

Notes: Interactive or batch S/R; extended regular expression support (cf. egrep). Operate on one machine or over a network. Small – easily run from diskette. Free for non-profit and non-government users.

Author: Anunga Muhummud / Intelligence Services, Australia (2002).

2002-09-25: v2.4.

Download (421K).

Penta Text Tools Online Reference Guide.

MiniTrue — Multiple file S/R with regular expression support.

* * * * *

[added 1996, updated 1999-12-23]

From the docs:

"MiniTrue synthesizes the functionality of such stalwarts as sed, more/less and grep while offering complete interactivity and a straightforward syntax." This flexible text search/replace utility is great if you need to search for – or replace – an instance of text across several files. MT incorporates a full screen file viewer which displays the context of matching text within a document.


Author: Andrew B. Pipkin (1999).

1999-12-23: v2.0.2b. Distribution file has both 16- and 32-bit versions. Now GPL'd.

Download (192K).

Go to the MiniTrue page for source code & Linux versions.

TexRep — Easy, multi-string text search and replace tool.


[added 1999-04-04, updated 2004-06-27]

One of the more comprehensible S/R tools listed here. Includes an easy command syntax, and the help screen can display a table of those hard-to-remember decimal code equivalents for special characters. Up to 15 string pairs may be input at one time. Can accept as input a file list, won't overwrite original files.

condensed SYNTAX:
texrep [-w] [-i]  s1:r1  [s2:r2] ... [@]infile  [-ofileout]
        -w  At times you may want to replace text only if it appears
            as a word. If so, add a -w before the word pairs.
        -i  Ignore case on the searches.
        -o option allows you to specify the output filename, with two variants:
           -ooutfilex.nam  names the output file in full
           use a period following the o to use the file
                           name, changing the extension to xxx (any set of
                           one to three characters.

Author: Stan Peters (1995). Suggested by Dan Dunfee.

Download (16K).

Alter — Small and fast global search and replace tool.

* * * *

Comments from a user: "My all-time favourite search-and-replace is Rob Flor's wonderful ALTER...Exceedingly fast, can accept wildcards _and_ make back ups, can be used as a filter, can mix plain strings with ASCII codes. Only thing extra I'd like is the ability to handle multiple search/replace strings at one time."

Syntax: ALTER filepec "search text" "replace text">outfile
DIR |ALTER "." "" >outfile
Features: Disadvantages:

Author: Rob Flor (1992). Suggested by Robert Bull.

Download (8K).

GSAR (General Search And Replace) — Multi-file, text or binary, search and replace.


[added 1998-07-04, updated 2005-08-22]

A simple search and replace tool that's (usually) easy on the fingers.

Usage: gsar [options] [infile(s)] [outfile]
-s<string> Search string
-r[string] Replace string. Use '-r' to delete the search string from the file
-i         Ignore case difference when comparing strings
-B         just display search & replace Buffers
-f         Force overwrite of an existing output file
-o         Overwrite the existing input file
-c[n]      show textual Context of match, 'n' is number of bytes in context
-x[n]      show context as a heX dump, 'n' is number of bytes in context
-b         display Byte offsets of matches in file
-l         only List filespec and number of matches (default)
-h         suppress display of filespec when displaying context or offsets
-du        convert a DOS ASCII file to UNIX (strips carriage return)
-ud        convert a UNIX ASCII file to DOS (adds carriage return)
-F         'Filter' mode, input from stdin and eventual output to stdout
Ctrl characters may be entered by using a ':' in the string followed by the
ASCII value of the character. The value is entered using ':' followed by three
decimal digits or ':x' followed by two hex numbers. To enter ':' use '::'
Notes: No regular expression support. Download packages include C source code. Released under GNU General Public License.

Authors: Tormod Tjaberg and Hans Peter Verne, Norway (1996, 2004).

Win32 console


CHANGE — Contextual multi-file search and replace tool.


[added 2002-11-15]

Change is an easy to use, basic search and replace tool that lacks regular expression support but does excel as an s/r tool with contextual awareness: you can replace strings based on the presence or absence of other strings which occur on a line (e.g., "replace apple with orange only if peach also occurs in line of text"). This capability can be finely tuned using Boolean operators ("replace apple with orange only if peach AND banana occur on same line"). More complex nesting of Boolean statements is supported. Best of all, Change's syntax is easy to comprehend.

Other features: Disadvantages:

Author: Bruce Guthrie (2002).

2002-08-10: v0208.

Download CHAN0208.ZIP (93K).

More in these pages from Bruce Guthrie.

GSR (Global Search Replace) — 32-bit interactive or c-line mode multi-file search and replace tool.

[added 1999-05-03]

Started with no parameters, GSR presents a dBase-like form to be filled in with filespec (wildcards permitted), text to search for, text to replace with, whether search will be case sensitive, whether replacements will be performed with or without user's approval of each one, and whether to process subdirectories. Or, GSR can be started with all parameters entered into the command-line. Compiled Clipper app, GPL w/ source.

Author: Phil Barnett (1999). Suggested by Howard Schwartz.

Download (223K).

sed – stream editor

Text search & replace (and more) using regular expressions, from the Unix world.

sed, a popular and powerful tool, is frequently used for text search and replace. It is also useful as a versatile filter / formatter. Requires facility with regular expressions. Three versions are listed here.

For more about sed, and seds, go to Eric Pement's sed . . . the stream editor.

GNU sed — 32-bit port of the GNU OS version.


[added 1998-09-02, updated 2005-08-03]

32-bit DJGPP build – requires 80386+ and a DOS Protected Mode Interface (CWSDPMI or other). Documentation is directed toward experienced users.

Author: Port by Juan Manuel Guerrero, Germany (2005).

2005-04-01: v4.1.4.

Binaries, manual
Docs: html/dvi/ps/pdf

U-SEDIT — A sed with clear documentation, 16-bit port from Unix.


[added 1998-09-22]

Mere mortals may want to look at this older sed version with approachable documentation. A 16-bit offshoot of GNU sed, it runs on DOS 2.0+.

Author: Mike Arst (1990). Suggested by Robert Bull.


EXE, docs
Updated docs


HHsed (sed15) — Another real mode sed.

[updated 2004-10-29]

From the docs, a few distinctive features:
This version otherwise appears to be equivalent to the UNIX version on the Sun4 computer... anything that sed did on that system, this version of sed will do the same on either a Sun4 or a PC under DOS.

Authors: Eric S. Raymond, David P. Kirschbaum, Howard L. Helman (1991).

EXE, manual
Source, history


TSP — Interactive text search program.


[added 1998-07-14, updated 2000-04-30]

TSP is an interactive text searcher which uses an internal viewer to display matching text within the context of adjacent lines (cf. MiniTrue). As you step through matches in each file you can write selected matching lines to a file or send them to a printer. During an interactive run you can also load a file with matching text into your favorite editor (default is Brief, or define another editor in an env. var.). TSP can run in a non-interactive mode with automatic writing of matching lines to a file or the printer. Handled a 1.25 MB test file with ease.

TSP [@][drive:][path]filename target_string [/C] [/AW] [/AP] [/AE] [/1] [/B]
     [/S] [/X:[@]file.ext] [/L:outfile.ext] [/A:attributes]

  [drive:][path]filename   File specification including wildcards.
  @[drive:][path]filename  Search list of file specification(s) in filename.
  target_string            String to be searched for.
  /C                       Use case-sensitive search, by default ignores case.
  /AW                      Automatically write results to a file.
  /AP                      Automatically send results to the printer.
  /AE                      Automatically edit files when a match is found.
  /1                       Find first occurrence of target_string in each file.
  /B                       Write results to Brief .APX file in First-Only mode.
  /S                       Searches subdirectories under specified directory.
  /X:[@]file.ext           Excludes subdirectories from subdirectory search.
  /L:outfile.ext           Name of output file. Default name is FOUND.TSP.
                           The extension is always .APX when /B switch is used.
  /A:attributes            Also searches files with the specified attributes.
                           Attributes can be H (hidden) and/or S (system).

Limitations: No regular expression support.

Author: Paul Bosselaers (2000). Suggested by Marianna Van Erp.

Download (25K).

grep – global regular expression print

GNU grep, egrep, fgrep — Search for text; basic and extended regular expression support.


[added 1998-07-23, updated 2005-05-27]

One of many available UNIX-derived greps for DOS, GNU's combines the functions of the traditional fgrep (search using fixed strings), grep (search using basic regular expressions), and egrep (search using extended regular expressions).

Two different packages are available: A 16-bit version, with a single EXE; and a 32-bit version with grep, egrep, and fgrep binaries that are identical except for filename.

Other differences between versions: The older 16-bit grep doesn't have a "recurse subdirectories" option, but the 32-bit version does. The 32-bit version is a DJGPP v2 build, requiring 80386+ and a DOS Protected Mode Interface (CWSDPMI or other).

Authors: 16-bit port by Stephen McConnell (1995); 32-bit port by Andrew Cottrell (2003).



EXE, manual

FGREP386 — Find files containing search string.

* * *

FGREP386, like many similar grep utilities for DOS, finds files in which a given string of text occurs. There are many free grep utilities available, and some support regular expressions and mimic their UNIX counterparts well. Not all are simple to comprehend, however. I use FGREP386 because of its small size, speed, option suite, and relative ease of use. It's only 8K and is optimized for fast operation (a 386 version is included). Its principle drawback is lack of regular expression support. Win9x: No LFN support / will not handle extremely long paths.

USAGE: fgrep [-Zv] [options] target {[@]file...}

switches: (edited for formatting)
-a ANSI mode).......................-r recurs. search (dirs/subdirs)
-b binary search....................-R recurs. search (subdirs)
-B case insensitive binary search...-s suppress **File header lines
-c case sensitive...................-t display found text only
-e return errorlevel only...........-v reVerse (negative) search
-f display **File header only.......-w whitespace not significant
-g[name] get frequency table........-x no logo
-i#[,#] define input search field...-Za echo command line to stdout
-j left justify output..............-Zb filter "bell" characters
-l line numbers.....................-Zd display current search dir
-m M-soft(R) output format..........-Zl send logo to stdout
-M M-soft(R) output format w/ path..-Zv ignore FGREP= env variable
-o# set max output length, 0-50000..-0 display no text
-p pause on full screen.............-1 disp. 1st matching line only
-@ generate ONLY list of matching file names
-? display this information using stdout
@file indicates a text file containing a file list

Author: Christopher J. Dunford (1997).

Download (34K).

XGREP — Tiny text finder with regular expression support.

* * * *

XGREP is yet another text finding utility. XGREP displays the lines in a file that contain a particular word, phrase, or pattern; can count those lines in which a particular pattern occurs; or can generate a list of files that refer to a given topic. Like a true grep program, XGREP supports "regular expression" searches. That is, one can perform flexible searches for text strings meeting a range of criteria (e.g., find text matching four consecutive numbers, restricted to digits 1-7). What separates XGREP from the freeware competition is its small size (3K) and the author's good documentation of regular expression syntax. One .COM file, compiled from 80x86 ASM source.

Usage: XGREP [-chlnsvyorx] expression [file ...]
-c Line count only.. -r Recursively search subdirectories
-h No file names.... -s Silent about inaccessible files
-l File names only.. -v Non-matching lines
-n Number lines..... -x No magic: all operators need \
-o Errors to stdout. -y Case-insensitive match
^ .. start of line...... repeat:. * ..... 0 or more times
$ .. end of line................. + ......1 or more times
.... wildcard.................... ? ......0 or 1 times
[] . character class............. \{m\}.. m times
[^]. inverse class............... \{m,\}..m or more times
\ .. quote next character........ \{m,u\}.m to u times
:a alpha...:c cntrl...:d digit...:g graph
:l lower...:n alnum...:p punct...:s space
:t print...:u upper...:x xdigit..:z ascii

Author: Robert Nordier, South Africa (1994).

1994-06-17: v1.03.

Download (13K).

AGREP — Fast grep-like util with approximate pattern matching capability.


[added 1998-07-03, updated 2005-12-08]

This program is intended for users familiar with regular expression syntax, but it has OK docs, good help screens, and a sufficient variety of useful examples. Copyrighted, free only for private, non-commercial use. From the docs:

AGREP is a powerful tool for fast searching a file or many files for a string or regular expression, with approximate matching capabilities and user-definable records...AGREP is similar to egrep (or grep or fgrep), but it is much more general and usually faster...It also supports many kinds of queries including arbitrary wild cards, sets of patterns, and in general, regular expressions. It supports most of the options supported by the grep family plus several more (but it is not 100% compatible with grep).
AGREP [-#cdehi[a|#]klnprstvwxyABDGIRS] [-f patternfile] [-H dir] pattern [files
-#  find matches with at most # errors     -A  always output file names
-c  output the number of matched records   -B  find best match to the pattern
-d  define record delimiter                -Dk deletion cost is k
-e  for use when pattern begins with -     -G  output the files with a match
-f  name of file containing patterns       -Ik insertion cost is k
-h  do not display file names              -Sk substitution cost is k
-i  case-insensitive search; ISO <> ASCII  -ia ISO chars mapped to lower ASCII
-i# digits-match-digits, letters-letters   -i0 case-sensitive search
-k  treat pattern literally - no meta-characters
-l  output the names of files that contain a match
-n  output record prefixed by line number
-p  supersequence search                   -CP 850|437 set codepage
-r  recurse subdirectories (UNIX style)    -s silent
-t  for use when delimiter is at the end of records
-v  output those records without matches   -V[012345V] version / verbose more
-w  pattern has to match as a word: "win" will not match "wind"
-x  pattern must match a whole line
-y  suppresses the prompt when used with -B option
@listfile  use the file names in listfile
\z          turns off any special meaning of character z (\# matches #)
^           begin-of-line symbol
$           end-of-line symbol
.           matches any single character (except newline)
#           matches any number > 0 of arbitrary characters
(a)*        matches zero or more instances of preceding token a (Kleene closure)
a(a)*       matches one or more instances of preceding token a
            (Use this as replacement for (a)+ which is not implemented yet.)
[b-dq-tz]   matches characters b c d q r s t z
[^b-diq-tz] matches all characters EXCEPT b c d i q r s t z
ab|cd       matches "ab" OR "cd"
<abcd>      matches exactly, no errors allowed in string "abcd"
            (overrides the -1 option)
cat,dog     matches records having "cat" OR "dog"
cat;dog     matches records having "cat" AND "dog"
Four compilations are available. The packages are substantial, and the EXEs are large (about 300K). All versions are 32-bit, require 80386+.

Authors: Sun Wu and Udi Manber, et al. DOS port by Tom Gries, Germany (1998).

DOS, OS/2, DOS box
Win32 only

DOS, OS/2, DOS box
All DOS & OS/2 EXEs, support files, source
Win32 EXE only
Win32, with source

Get more info at Tom Gries's AGREP page.

dg (data-grepper) — Search for complete records based on search phrase.

See extended description.


YANK — Replace or delete lines of text containing search string.

* * * *

[added 1998-04-19, updated 2000-03-02]

Like KLine, this program can be used to strip out entire lines containing a search string, but it also offers the option of replacing the line with another string rather than deleting it. Search and replace strings can be any combination of literals and ASCII codes. Other differences from KLine: 1) YANK handles longer lines; 2) does not create a backup file; 4) "can read from another file both the search and replace string specifications or replacement text image (65,534 char. max; search string limit 4,095 char.)."

Limitations: Unlike KLine, YANK doesn't output number of changes made per file. Works fine on my MS-DOS machine – but can't get it to work properly under OpenDOS.

YANK [/i] filespec "[srchstrng][^[x]chr,][...]" ["[replstrng][^[x]chr,][...]"]
YANK [/i] filespec @scriptfile or YANK [/i] filespec "srchspec" @imagefile insensitive

Author: Clay Ruth (1996, 2000). Suggested by Marianna Van Erp.

2000-01-14: v1.3, part of Clay's Utilities for MS-DOS.

Download (398K).

Go to Clay's Utilities for DOS Batch Processes for upgrades of some other utils in the package, Windows version, info, license agreement & more.

KLine — Delete lines of text containing search string.

* * *

KLine deletes entire lines which contain a search string. Accepts wildcards and creates a backup of original file. Outputs the number of lines killed per file. Case sensitive/insensitive options.

Limitation: KLine will truncate lines longer than 255 characters.

Usage: KLine text_file(s) "offending string" [/c (case sensitive)]

Author: David Daniel Anderson / Reign Ware (1994).

Download (13K).

Go to Top | Front Page ]

©1994-2004, Richard L. Green.
This Edition ©2004-2005, Richard L. Green and Short.Stop.