MiniTrue is an overlooked search/replace utility, available for both MS-DOS and Linux. The DOS versions come in 16-bit (mt.exe) and 32-bit (mtr.exe) varieties. MiniTrue (mtr) was written by Andrew Pipkin and is free software, distributed with the source code under the GNU General Public License. Yes, it has a weird name. From my experience with Win32 systems, MiniTrue works best under Windows 9x and sorta half-way under Winows 2000. I have used it to change thousands of web files on a Win2K box, so it is a usable piece of software. I have not tested it on WinXP or WinME at all. You can download precompiled binaries (executables) and the source code here:
The following comments refer to MiniTrue v2.0.2 (Alpha #3), which is the latest release version available.
Display file1,
highlighting the find term if it exists, and
prompt the user to replace here or skip to the next match. A backup file is made by
default. After the first file is processed, proceed to file2 and so on.
One hyphen separates the files from the find strings.
Option switches are indicated by
-n
means "replace automatically" (no prompting)
-o
sends the changed lines to stdout instead of to the pager.
-o+
sends both the changed and the unchanged lines to stdout, just like sed.
Display file1,
highlighting the find term if it exists.
At the end of file1, proceed to display file2 and so on. No backup
file is created, since the files are not altered. Use "double quotes" if the search term contains
angle brackets, pipes (|)
, or spaces.
Alternate syntax. Note that two hyphens allow the user to put the find or find = replace pattern before the list of files. For a list of all options, go here.
I need to find out how often and where home.html occurs in my files
Recurse through subdirectories (-r)
Send results to stdout, not to viewer (-o), add line numbers (-o#)
This command is identical to: grep -inr "home\.html" *
After checking first, I do the replacement
No prompting, replace automatically (-n)
Recurse through subdirectories (-r).
Numbered backups always created (info~1.ht1, main~1.ht1 ...
)
on find/replace (yes, I lose the LFN on backup files)
Some joker used three periods .../
to navigate up two levels, so I gotta fix it.
Turn off regex expansion (-x-)
Keep a list of hits and results (-k)
No prompting, replace automatically (-n)
Backup file has .BAK
replace original filetype (-b)
Somebody misspelled Adolf's name. Fix it, even if it's capitalized.
Whole word match (-w)
Correspond case throughout whole word (-c+), so
adolph --> adolf, Adolph --> Adolf,
and ADOLPH --> ADOLF.
Or, correspond case only on first letter (-c~), so
adolph -->adolf, Adolph --> Adolf,
but ADOLPH --> Adolf (This isn't one I use much)
I have a script file (script.txt) for my changes,
plus a list of files to alter in FILELIST
Get find/replace strings from input file script.txt
(-i).
If the script file is omitted, get find/replace pairs from console.
Use FILELIST
to get names of files to process (-@).
If the filelist is omitted, get list of names from console.
Keep a list of hits and search data (-k)
Send results to console, not to viewer (-o)
Use input list of STRINGS
to find or replace
Though MiniTrue is a great program, it has aggravating misbehaviors under Windows 2000, which is what I use at work. Fortunately, those misbehaviors are predictable, and there are workarounds.
This means that if you type a command like:
mtr SomeValidLongname*.htm - only = merely
which ought to expand normally under Windows 9x or Windows 2000 (assuming those files exist), nothing will happen at all. To properly handle the files, you must use 8.3 filename conventions, like so:
mtr Some*.htm - only = merely mtr some* - only = merely
Then, SomeValidLongname01.htm, SomeValidLongname02.htm, and SomeValidLongname03.htm will all be matched and changed. The new files will receive the long filename, but the backup files be renamed to an 8.3 format (See point #3 below).
With mtr, the 32-bit version of MiniTrue, you will get a flashing cursor on the next line, but nothing else. (This bug appears in Windows 2000, but not in Windows 98). You may think that MiniTrue is hung up, but the workaround is to press the command key followed by the ENTER key. If viewing the help menus, you must press the movement key twice (i.e., instead of pressing space to page down, press space-space. Instead of pressing b to move backwards a page, press bb). Sometimes you have to press a command key followed by the ENTER key. This behavior is somehow related to how Win2K handles the console, which is not the same as how Win9x handles the console. (Maybe the author can borrow some code from the Windows version of less or something.)
The simplest fix for this problem was sent to me by another user. Just use mt, the 16-bit version of MiniTrue, instead. He reports that the 16-bit version will not handle as many files as the 32-bit version (I don't know, since I haven't tested it myself), but I can confirm that on a Win2000 system, the 16-bit version does handle keyboard input properly.
The following is not complete, but since it may be a long time before I have time to finish it, I thought it best to post what I have in its provisional form.
The worst thing about MiniTrue is that if you tell it to fix a bunch of files
on a system that uses long filenames, the new file still keeps the long filename
all right (such as stewardship.html
),
but the backup (original) file often gets changed to an 8.3 name like
stewar~1.ht1
. So as long as your replacements are perfect, you have nothing
to worry about.
But if you should make a mistake and want to revert to your original filenames,
you may find yourself in trouble. This happened to me once, after changing several
hundred files with long filenames. I accidentally changed hundreds of *.html
files with an untested pattern. I had guessed wrong. The new/changed files had the
right long filenames, but the changes were in the wrong place.
I don't remember exactly what I did to recover from that disaster, but it was recoverable.
I think that none of the short filenames used ~2
or ~3
, so
I could rely on the fact that the first 6 characters of the "bad" files and the "good"
files were always the same, and then I did a "for..in..do" loop involving file
renaming and substring matching.
The lesson here is to use short (8.3) filenames as much as possible, if you can.
If you must change a group of files, before you use the -n
(no promping) switch,
use the selective-preview mode (the default mode for MiniTrue) on a few files, and
then when you are sure the replacements are what you expect, you can invoke MiniTrue
with the -n
switch on the rest.
I think there is a work-around that will preserve long filenames in the backup files that MiniTrue creates, but I don't recall what it is. If someone else finds out, let me know. Thanks.
Last updated: Dec. 3, 2003
E-mail your comments or corrections to: Eric Pement