Home

 

Examples

 

Technical

 TextMaestro

 

2003 TextMaestro Technologies

 

  Examples

  Example 1

  Example 2

  Example 3

  Example 4

  Example 5

  Example 6

  Example 7

  Example 8

  Example 9

  Example 10

  Example 11

  Example 12

  Example 13

  Example 14

  Example 15

  Example 16

  Example 17

  Example 18

  Example 19

  Example 20

  Example 21

 

 

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

2. Meaning of Instance Icons

3. Overrule Instances

4. Write Results to Files

 

 

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.

Find:

<*image*.gif*>

Replace:

< <*1>image<*2>.gif<*3> >

The above macro should look like this in its define dialog, which you open by double clicking on the macro.

 

Note the use of wild-card (*) for both Find and Replace, and above all, the use of Compact construct knob in this definition, without which parsing will concoct unexpectedly large string for Find. See details on Compact Construct here.

 

 

(5) Hit Search in files using macros in library button, which will do the following:

  • Load selected files from main file-list to the Convert Files dialog

  • Load text of each file from disk into memory

  • Parse text in memory for any instance of Find defined by the macro

  • Populate the two lists with the results.

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:

This instance has source access information. I.e., double click on this item, it will take you straight to the source where this instance is located.

This instance does not have source access information, because Build source access table check box was turned off. We often turn off this check box to reduce memory usage for extremely large files.

When an instance has this icon, double-clicking on it will not take you to the source code.

You will not see this icon, if you have Build source access table checked, which is the default behavior.

This instance has been marked as skipped. That means if you hit Write to files button now, the scheme will skip this instance while writing takes place.

This instance has been marked as manually modified. That means if you hit Write to files button now, the scheme will use the text that you have supplied in the Replace edit box (the lower edit box) instead of what the conversion scheme concocted originally.

 

 

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:

Preview of original Instance 4:

Preview of Instance 4 after modification by the user:

 

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:

 

Select all items in the left list.

 

Hit on Batch name output files button. This will open this dialog.

 

You will find three options here. Using these options, you can generate names for output files almost anyway you want to. We will leave it on you to make experiments.

 

Choosing Same as input names from Options 1: Batch Naming, we get the following:

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.

Top