Replace Text (rt)

PillarSoft Utilities, Copyright 2003, PillarSoft

 


Description

Replace Text (rt) provides an easy to use command line interface for search and replace operations on ACSII based text files. Words and phrases are both supported for search and replacement in Case-sensitive or non-case-sensitive form.

Using the Recurse option, it is also possible to search subdirectories recursively for any given filename or wildcard specification and replace multiple words or phrases in multiple files. The Verbose option allows a visual report of every file accessed as well as how many "hits" the program finds in terms of it's search and replace mission in each particular file. A final tally of search and replace "hits" is always produced by default at the end of each program run.

Logging is available on each run. The logfile is written in the home directory of the Replace Text (rt) executable and is named Rt.Log. Rt.Log is rewritten with each running of Replace Text (rt) that requests Logging as an option. By selecting the O option, logfiles will contain Only the names of files that contained the SearchTerm and have been changed.

Complex changes may be written to File and read by the program. Reasons to use this method may be:

 

Syntax

  rt FileName, SearchTerm, ReplaceTerm, Option

 

Parameters

Parameter
Data Type
Purpose
Value
Default
Required
FileName string Name of file to operate on. May be filename only if in the current directory, a fully qualified filename if located elsewhere or a filename spec with wildcards. (example: *.txt   or   c:\apps\*.txt) N/A N/A Y
SearchTerm string Text to search for and replace with ReplaceTerm. Complex SearchTerm's may be read from file. (See /F parameter) N/A N/A Y
ReplaceTerm string Text that will replace SearchTerm. Complex ReplaceTerm's may be read from file. (See /F parameter) N/A N/A Y
Option string Options may be listed in any order.

C - Indicates a Case-sensitive search. Defaults to non case-sensitive searches when this Option parameter remains unused.

F - Retrieve SearchTerm and ReplaceTerm from a created File. The file must reside in the rt.exe directory and must be named rt.dat (See Notes for more)

L - Logging. Logs all files accessed and the numbers of "hits" and replacements made in relation to each file.

O - Log Changes Only. Logs files that contain "hits" and replacements only. The Logging option is implied by selecting this option and does not have to be set separately.

R - Recurse subdirectories. Searches subdirectories and operates on all files of the same name or wildcard specification.

V - Verbose. Each file that is accessed is listed and reported on. (Number of occurances and replacements) By default, only the total number of files, occurrances and replacements are reported.

N/A Non-sensitive
Non-logging
Non-verbose
Non-recursive
Non-file based
N

 

Notes

 

Return Values

Value
Error
0
No errors
1
File not found
2
Parameter incorrect
3
Unable to read file or file data has no value
4
Could not write to file, may be read-only
5
RexxUtil could not be loaded
6
Operation canceled by user

 

Example(s)

 
Read C:\MyFile.txt, locate instances of Old Text in any case and replace it with New Text. (Upper or Lower)

  rt C:\MyFile.txt, Old Text, New Text

 
Read C:\MyFile.txt, locate instances of Old Text case-sensitively and replace it with New Text.

  rt C:\MyFile.txt, Old Text, New Text, /C

 
Read all *.txt files in the C:\Apps directory, locate instances of Old Text (any case) and replace it with New Text. Report number of hits and replacements in each file "on screen" and in a logfile. (rt.Log)

  rt C:\Apps\*.txt, Old Text, New Text, /VL

 
Read all ReadMe.txt files in the C:\Apps directory and all of it's subdirectories, locate instances of Old Text (Case-sensitively) and replace it with New Text. Report number of hits and replacements in each file.

  rt C:\Apps\ReadMe.txt, Old Text, New Text, /CVR

 
Read all ReadMe.txt files in the C:\Apps directory and all of it's subdirectories, use Old Text and New Text that is read from the rt.dat file. Log changes only.

  rt C:\Apps\ReadMe.txt,,, /FOR

 
Display syntax help.

  rt ?

 

/F Data Examples

Here are three examples of rt.dat file content when using the /F parameter.

Example 1:
SearchTerm
This is text to replace, it can be almost anything.
ReplaceTerm
This is the new text I want to use.

rt.dat contents: Notice ReplaceTerm always starts on the line following the ~END~ delimiter from SearchTerm
This is text to replace, it can be almost anything.~END~
This is the new text I want to use.~END~


Example 2:
SearchTerm
This is text to replace
It's on two different lines
ReplaceTerm
This is the new text I want to use.
It will be spread over five separate

lines that include an empty line at the end.

rt.dat contents: Notice how adding empty lines in ReplaceTerm before the ~END~ delimiter adds empty lines to the output.
This is text to replace
It's on two different lines~END~
This is the new text I want to use.
It will be spread over five separate

lines that include an empty line at the end.

~END~


Example 3: Like above but extraneous data is added after the second ~END~ delimiter without affecting operation.
SearchTerm
This is text to replace
It's on two different lines
ReplaceTerm
This is the new text I want to use.
It will be spread over five separate

lines that include an empty line at the end.

rt.dat contents: Notice that nothing after the second ~END~ has any effect on the search and replace operations.
This is text to replace
It's on two different lines~END~
This is the new text I want to use.
It will be spread over five separate

lines that include an empty line at the end.

~END~
This text has no effect on the search and replace because it is after the second ~END~ delimiter.
You can write all the notes you want down here or even save some S&R's that you might want to use
again. I kept our first example down here and rt.exe won't bother with it.

This is text to replace, it can be almost anything.~END~
This is the new text I want to use.~END~

Remember that line breaks will be found or replaced just as they are specified in the rt.dat file.  


Copyright 2001 - 2003, PillarSoft
All Rights Reserved