2003 TextMaestro Technologies
Example 18: Multi-file Find-and-Replace.
Have you ever wished that you could see all find-and-replace instances before you actually perform the replacement? And, sometimes even skip some of the instances, or even hand-edit some of them? Now you can with TextMaestro. Fear no more when you perform a massive find-and-replace in multiple files under batch mode. Because you can preview your act before you actually submit the replacement.
Using this feature you can perform multi-line search involving wild-card and type-card on a set of files that can hunt down your text of interest to the finest control. Yes, it is a behemoth search tool using a grammar easier than regular expression.
Let us begin with an example. Suppose we want to preview instances of all .gif images in a set of .html files. Here is the step by step process. We will discuss:
1. Preparation and Previews: Top
(1) Launch the application.
(2) Drag the .html files of interest onto the list view as shown below.
(3) Click on Text Conversion button while holding down the Shift key.
Make sure the .html files on the list view are all selected, if they are not.
Batch Text Conversion dialog will appear as shown below. Alternatively, simply hit Ctrl+Shift+F. (See 13: Text Conversion in Batch mode for details on various controls found on this dialog).
(4) Before you do anything here, you must set up a library.
Hit the Library button to open the following dialog, where we define a new library called Prev-Example (see left list below). In that library, we define a new macro (see right list below).
We use left and right Add buttons to add a library and a macro, respectively. Below is the macro that we defined.
(5) Hit Search in files using macros in library button, which will do the following:
Expect to see the following:
Files marked with indicate that at least one instance was found in it, while indicates that no instance was found in this file.
2. Meanings of Instance Icons: Top
Various icons are used for instances (right list above). They have certain meanings. They are listed below. For all cases however, note that alternate colors (blue and red) are used to distinguish instances from one macro to another macro. Here is an example.
Suppose the library contains 3 macros. (In our example we had only one macro). Also suppose, for a certain file, first macro generated 8, second macro 7 and third macro 6 instances. Then the right list will display total 21 instances, where first 8 instances will be in blue icons, next 7 in red icons and the last 6 in blue icons again. Since our library here had only one macro, we saw only one color (blue) icons.
Various Instance Icons:
3. Overrule Instances: Top
Consider the above example. Note samples.htm file has four instances. At this stage if you proceed to write the preview results to some files, these four instances will be written as you seem them. However, what if you want to skip the second instance, and make some last minute changes in the fourth instance? This type of skip or last minute modification is commonly called overruling the preview.
To skip an instance, simply click on it and hit the skip button. You will notice that the instance has assumed a different icon.
To modify an instance, simply make changes in the Find and Replace Preview window (a secondary window pops up as you click on an instance), and hit on Save changes button.
Suppose we marked the 2nd instance as skipped, and 4th as modified. Expect to see the following:
4. Write Results to Files: Top
After the preview instances are constructed, you can write the results to files, if you choose to. However, you must specify names for output files first. Here are the steps:
At this point if you hit Write to files button, TextMaestro will obey your order as you wished for --- replace all instances; however, for the last file skip the 2nd instance, and for the 4th instance, use user-supplied text.
Here is the message from Message Window.