| Home | Simple version | Whole Word version | Regular Expression version |

Free Download & Tutorial: How to Perform Multiple Search and Replace Operations on Multiple Files Using a Simple Replacement List

By Howard Charles Best, May 18, 2010

(llbest.com)


This tutorial assumes the following 3 things:

1. That extensions for known file types are not hidden. (1. Click Start / My Documents. 2. Click Tools / Folder Options…. 3. Click the View tab. 4. Make sure that Hide extensions for known file types is unchecked.)

2. That you have Notepad2 or a shortcut to it on your desktop.

3. That you have installed Perl according to the tutorial at:
http://llbest.com/PerlProgramming.htm.


On this web page:
A. Introduction
B. Get the Free Download
C. Main Features
D. Example
E. Preview Mode
F. Subfolder Support
G. Conclusion


A. Introduction

This web page is a tutorial on how to use a free Perl program to do search and replace operations using a simple internal list of replacement pairs. The replacement pairs may contain special Unicode characters in which case the .bat file must be saved as a UTF-8 file without signature.


B. Get the Free Download

The free download (_SandR_Simple.zip) contains the following 2 files:

Screen capture of Notepad2 showing the 2 files

1. Download now (1.75 KB).

2. Unzip _SandR_Simple.zip to a folder called _SandR_Simple.


C. Main Features:

1. Multiple files can be changed in one fell swoop.

2. These files can be a mixture of regular ANSI and UTF-8.

3. Changed and unchanged files can be easily separated by sorting by “Date Modified.” (Unchanged files are not rewritten.)

4. A log file is created which itemizes the number of changes by file and within files, by replacement pair.

5. If the .bat file is renamed (in order to create specialized versions, for example), then the new .log file will automatically have the new name.


D. Example:

Suppose that you want to change every occurance of *r to *R and every occurance of é to e in a large number of .txt files.

Here’s how to do it:

1. Drag and drop the _SandR_Simple.bat file’s icon onto the Notepad2 icon. Then you will see lines 22 through 33 as follows:

Note: # at the beginning of a line indicates that the line is a comment, so the Perl program simply ignoes it.

Here is what _SandR_Simple.test looks like:

2. Double click _SandR_Simple.bat file’s icon. Then you should see the following:

Screen capture of search and replace operation

2 new files are created:

Screen capture showing the 4 files

_SandR_Simple.test was copied to _SandR_Simple.txt and then the search and replace operation was performed:

Here is what the LOG file looks like:

(_SandR_Simple.log)


Note: Lines 24 and 25 of _SandR_Simple.bat uses what are called Regular Expressions. For more examples of search / replacement string syntax using Regular Expressions, see
http://llbest.com/RegularExpressions.htm. For a tutorial on Perl regular expressions, see http://perldoc.perl.org/perlretut.html. For a reference, see http://perldoc.perl.org/perlreref.html.


E. Preview Mode

The .bat file contains the following in lines 14 through 16:


F. Subfolder Support

The .bat file contains the following in lines 18 through 20:


G. Conclusion

Now you are ready to perform multiple search and replace operations on any number of files:

1. Be sure to keep backup copies of all of the files until you are sure that the search and replace operations were done correctly.

2. Copy the files to be changed to a temporary folder such as C:\Temp2.

3. Copy _SandR_Simple.bat to the same folder.

4. Comment out lines 30 and 31 and then add your own particular replacement pair line(s).

5. If appropriate, comment out line 25 and then add a file name mask assignment line which fits the particular files that you wish to change.

6. Double click the _SandR_Simple.bat file’s icon, and if all goes according to plan, all of the files will now be edited automatically!


| Home | THIS WEB PAGE URL: http://llbest.com/_SandR_Simple.htm | Simple version | Whole Word version | Regular Expression version |