Welcome to


DOGSBYTE.COM




MultiSub 2005
A FREE utility for batch Find/Replace







MultiSub Functions

Use
MultiSub

for
batch
Find
&
Replace


*

Supports
regular
expressions


*

Find
text
from
file
contents

*

Replace
text
from
file
contents


*

Batch
mode

*

Ideal
for
WebMasters

*

Use
MultiSub

for
batch
Find
&
Replace


*

Supports
regular
expressions


*

Find
text
from
file
contents

*

Replace
text
from
file
contents


*

Batch
mode

*

Ideal
for
WebMasters

*

Use
MultiSub

for
batch
Find
&
Replace


*

Supports
regular
expressions


*

Find
text
from
file
contents

*

Replace
text
from
file
contents


*

Batch
mode

*

Ideal
for
WebMasters

*









Adjusting the window size


Loading Files


Find & Replace - Using Text Strings


Find & Replace - Using A Regular Expression


Find & Replace - Using Files

State Files


Batch - State Mode


Batch - List Mode

Find/Replace on a per file basis


Check Buttons


Options


Settings


Using Multi-Sub to provide the capability to include files in HTML




The various areas of the main tab are shown here.




Window size
Adjusting the window size

To adjust the window size, click on the two green arrows at the top right of the MultiSub window.

To reset the window, double click on the "Resize window" text.




Loading files Loading files

To load files into the FileList, three methods are supported.

Note,
the small green arrow at the top of the FileList allows the list to be expanded or contracted.

Add
Click the Add button, navigate to the folder(s), click on the relevant files. Multi-select is supported. To select individual files, hold down the Control key and click each in turn, to select a range of files, click on the first, hold down the Shift key and click on the last. Selections can also be made using any combination of the Control key and Shift key methods.

Folder
This is particularly useful if all files are in the same folder tree. To specify the top of this tree, click on the Folder button, navigate to the required folder. Alternatively, type in the required path.

Once this folder has been specified, files can be added using the three short cut buttons which add all files of type "*.txt", "*.htm*", "*.php" respectively, to the file list. A fourth button called Get Filter will add any files that match the Get Filter box. So to load all files with a given name such as Test_1.text, Test_2.text etc., the Get Filter box can be set to Test_*.text, then press the Get Filter button.

Additional files can be loaded using the Add button, files can be removed from the list using the Remove button. The Remove button supports multi-select, so multiple files can be removed in one action.

An additional button is present called Sub-Folders, when set, the short cut buttons and Get Filter button will add all files in the folder and also any matching files in any sub-folders that are present in the selected folder.

Drag/Drop
Files can also be added using drag and drop, select one or more files and drag onto the FileList.


Using any method, the same file cannot be added twice.


Once one or more files are loaded, a files content can be displayed in the TextPane by clicking on the relevant file in the list. The files can be ascending/descending sorted by clicking on the column headers.

If the file selected file (being displayed in the text window) is HTML, PHP or XML, the option to highlight the syntax will be shown.




Find & Replace Using Text Strings


Load one or more files and select one of them (its contents will be displayed in the TextPane). For the purposes of doing a basic Find/Replace, deselect the Use Regular Expression checkbox and click the Interactive checkbox.

In the FindBox, enter a text string that is present in the file. As you type each character, the Find results will be updated immediately showing you the matches for whatever is present in the FindBox. This is the function of the Interactive button. (If the Interactive button were deselected, the results are not displayed until the Find button is clicked).

The Find string is highlighted in the TextPane, the number of matches are shown above the ResultsPane, the details of each match is shown in the ResultPane. To jump to a particular match, click on that specific match in the
ResultPane, the TextPane will jump to that position. The file text position will be maintained, even if a subsequent match is not obtained. Alter the scroll position to view an alternative area of the file.

To see the same results, but for a different file, simply click on the relevant file in the FileList.

A replacement string can be entered into the ReplaceBox. By clicking Replace, MultiSub cycles through all files in the file list and replaces all occurrences of the Find string with the ReplaceBox string. On completion, MultiSub will jump to the ResultsTab, this shows which files were changed and how many replacements were made. The table of results can be saved to a file from this tab.

The Find All button allows you to search all of the files, without actually doing the replace operation. So this is in fact the same as clicking the Replace button, except that it does not alter any files.




Find & Replace Using A Regular Expression

This works exactly as before except that the Find text can be a regular expression. Regular expressions (or RegEx for short) can be hard to grasp, but they are essentially a sequence of criteria. RegEx are very useful where a simple string based search is not selective enough. Everyone knows what can happen if you replace a string without being specific enough, you can end up with many unintentional substitutions and your whole document can even end up being unreadable! Using RegEx, allows very simple to very complex selections to be made.

Deselect the Interactive box. Select the "Use Regular Expression" checkbox, you can now enter a RegEx into the FindBox. For example, to match four letter words beginning with b and ending in t, the corresponding RegEx would be b..t. This means the word must begin with b, end with t with two characters in between.

RegEx are enormously powerful and allow very complicated selections to be made, which otherwise would need to be done with in a series of tedious manual steps.

MultiSub supports various RegEx options which are covered later.

A tutorial on RegEx is given here. For more comprehensive education on RegEx, there are many excellent books and web sites that provide tutorials on developing regular expressions. It does not make sense to produce yet another site, however a quick reference guide is accessible from the MultiSub menu.




Find & Replace Using Files

MultiSub allows the contents of a file to be used as the Find text. Select the FileMode checkbox which appears to the left of the Find button. A new FindPane is opened. At the top of this pane is a small file icon which allows a file to be loaded into the FindPane. The arrow icon next to it to the right, is a reload button, that allows the file to be reloaded should it be altered using an external editor. Alternatively, you can type directly into the newly opened pane.

Once loaded, MultiSub will use the entire contents of the file specified as a giant Find string, so the presence of a large quantity of text can be searched for within a file. This is particularly useful for a web site owner who may have hundreds of HTML files, each containing a block of code that represents a menu, or an advert or whatever. By copying out the relevant text and pasting into a file, the offending text can be searched for and removed/changed in each and every HTML file.

A nice feature of MultiSub, is that if the Find text requires an edit, this can be done directly in the pane. Just click on the relevant part of the text and edit as needed. Once changed, a disk icon will appear, allowing the modified text to be saved back to the original file.

Case sensitivity can be selected as well as the option to ignore surplus whitespace.

The Replace text can be a string, or by using the file mode checkbox to the left of the Replace button, a file can also be used. The 'Replace' text that appears in the pane, can also be reloaded, edited in the pane and saved as before. For example, if you wanted to replace a block of text with another block of text, then the find and replace text can be specified in two files rather than having to type it in.

MultiSub also allows insertion rather than replacement. By selecting Insert, the replacement text can be added and the find string retained. The insertion can be before or after the find text. The option is present to insert a newline character between the find text and inserted text (or between the inserted text and the find text).

It may be obvious already, but Find/Delete is achieved by specifying no replacement text.




State Files
State Files


You can store the current state of MultiSub at any time using the SaveState button which creates a 'state file', this can be loaded at a later date with the LoadState button. All settings are restored. If using the content of files as the find or replace text, note that the state file stores the file paths not the file contents.

A state file can be used to restore a setup and is also used when using MultiSub batch modes. Two batch modes are present, for the majority of the time users are will typically only require Batch-State mode, which is enabled by default. The state files differ between the two modes.

Batch-State Mode;
In Batch-State mode (the default batch mode) and when saving a state file, it is stored with the extension ".msf". Batch-State mode allows a collection of state files to be loaded and executed in sequence. The majority of users use this mode.

Batch-List Mode;
In Batch-List mode (i.e. where "Use Pair List" is checked), state files are stored with the extension ".mlf". This mode was introduced in V1.2.0 by popular request and would typically be used when find/replace pairs are readily available and are perhaps extracted from a database or spreadsheet. This is used by a minority of users.

Note that when loading or saving a statefile, the file dialog will only display the files that are appropriate to the current mode. So in Batch-List mode and when loading a file, only ".mlf" files are shown on the file dialog.




Batch State Batch State Mode


As previously described, the BatchStateTab allows a collection of state files (.msf) to be loaded and executed in sequence. State files can be loaded in exactly the same way as the file list.

Each state file is loaded, the Find/Replace is executed for each file listed in that state file, the next state file is loaded and so forth. The results are shown on the ResultTab, this lists each state file, the relevant backup folder name made before it was run and the number of substitutions made for each file that was present within it.

The sequence is;

For each state file loaded
  For each file listed in that state file
    Do the find/replace operation specified in the state file
  Next file
Next state file

The Run All button will execute all state files, Run Selected will execute on only those state files selected in the pane.

The Find All button will execute all state files, but will not actually do the replace. The Find Selected button will do likewise on the files selected in the pane. The batch Find buttons allow the user to check that all state files run cleanly before proceeding with a batch replace operation.

The current state of the BatchStateTab can be saved to a batch file which can be reloaded at a later date. A batch file is stored with the extension ".msb". Thus a batch session can also be restored.




Batch List
Batch List Mode


On the MultiSubTab, a check box is present marked "Use Pair List". When selected, the BatchStateTab is disabled and the BatchListTab is enabled.

The BatchListTab allows a text file to be loaded of the form;

FindStringA , ReplaceStringA
FindStringB , ReplaceStringB
FindStringC , ReplaceStringC
etc.

This file is referred to as the 'pair list'.

On the SettingsTab, the delimiter may be set as a comma (,), slash (/) or pipe (|) character.

The pair list (the source text file) would be generated by the user and would typically be extracted from a spreadsheet or database. The file can be loaded using the "Load List" button, or drag/dropped over the find/replace pairs table.

Each line of the file represents a find/replace pair. The find/replace pairs are loaded into the table and can be executed in a similar manner as previously described for the BatchStateTab.

The sequence is;

For each find/replace pair
  For each file in the file list
    Do the find/replace operation
  Next file
Next pair

The Find element of each pair can be a text string or a regular expression.

Thus each find/replace pair will be executed on all files loaded in the FileList. The same buttons are present as Batch-State, Find Selected, Find All, Replace Selected, Replace All.

The "Trim" checkbox, allows the user to remove any leading and trailing spaces from the find/replace pairs loaded (the pair list file used for the source of this list remains unchanged).

Note that when storing a state file in Batch-List mode, the file path of the pair list containing the find/replace pairs is stored, not the content of the file, hence the pair list file cannot be discarded.

When using Batch-List mode, the MultiSubTab has modified controls. The user can step through each find/replace pair using the arrow keys below the Find and Find All buttons. This is useful to check the results for an individual find/replace pair on any given file.




Per File
Find Replace on a per file basis


If the requirement is to make a find/replace operation on a per file basis, e.g.

For n = 1 to the number of pairs/files
    Do find/replace operation for pair n on file n
Next n

MultiSub does not support this operation, but MultiSubLite does. The 'Lite' version of MultiSub is intended for scripting, where a command file can be constructed (as a text file) that contains the required sequence. This command or batch file can then be executed using MultiSubLite.

Many users use this for situations where each file requires a different edit, so for example in file 1, the string "Page 1" must be changed to "Page 2", in file 2, the string "Page 2" must be changed to "Page 3".

The required per page edits can often be easily constructed in an Excel spreadsheet, making use of Excel functionality to build up the various columns. By also including the MultiSubLite command words in the spreadsheet columns and then writing this spreadsheet out as a text file, a batch file is created which can be simply run on a DOS command line. MultiSubLite is ideally suited where per file edits are required, especially if such operations must be repeated on a regular basis (in that the user can run a stored script to perform the required task).





Find All Buttons Find All Buttons

The MultiSubTab and batch tabs have Find All buttons. These run the Find or Batch operations but do NOT create any modified output files.

For the MultiSubTab, the
Find All button allows the number of matches for each file in the file list to be determined, without actually performing the change. The Find All button allows the user to check that the intended Find string is correctly matched in all files.

For the batch tabs, the
Find All and Find Selected button allows the state files of find/replace pairs to be loaded and executed in sequence, to ensure that no errors occur. The find all/selected buttons allow the user to check that the intended Find string is correctly matched in all files and also checks for any errors that may be present in the state files or pair list.




Options Options

There are various options which are enabled depending on the 'context'. For example, if Use Regular Expression is selected, the RegEx options are enabled.

Here is a list of the options and their function;

Interactive? - Evaluates the Find string, whenever the contents of the FindBox is changed. This is useful for fine tuning a string or RegEx. Using Interactive mode with Use Regular Expression is not recommended however, since the syntax of the RegEx is evaluated on every key stroke. It is better to deselect Interactive, enter the RegEx, then turn Interactive back on to fine tune a RegEx expression.

Save State - This allows a "state" file to be saved which stores the current setup. So whatever files, options etc. are set, are stored and the session can be resumed at a later date. A state file is loaded using the Load State button.

Load State - This loads a previously saved state file, restoring MultiSub to whatever state it was in at that time. State files can be overlaid, in that having loaded a state file, another can be loaded immediately afterwards. The state specified by the last state file loaded will dominate, but the file list for example will contain the accumulated list of each state file loaded. As mentioned previously, the type of state file that can be loaded depends on which mode MultiSub is in.

Pane Size - The height of the TextPane is adjustable, mouse over the junction between the TextPane and Result/Find/Replace panes, press the left mouse button and drag the border to the new position. If a file is being used for the Find and/or Replace text, the width of the panes is adjustable in the same manner. (The chosen pane sizes are stored in a state file). The FileList can be expanded or contracted by clicking on the green arrow at the top of the file list.

Insert - MultiSub also allows insertion rather than replacement. By selecting Insert, the replacement string can be added and the find string retained. The insertion can be before or after the find text. The option is present to insert a newline character between the find text and inserted text.

Insert Before - In Insert mode, the replacement text is added before the find text.

Insert After -
In Insert mode, the replacement text is added after the find text.

Add Newline -
In Insert mode, this option allows a newline character to be added between the find and replacement text. (For the technically minded, a CRLF character is inserted but alternative new line characters can be selected on the Settings menu).

Ignore case? - This is enabled when RegEx is disabled. When selected, the uppercase and lowercase versions of characters are considered to be identical.

Ignore Pattern Whitespace? - This is enabled when RegEx is disabled. When selected, any white space that may occur before/after/within the find text is ignored. For example, a find string of " A A" would establish a match to the text "AA".

Use Regular Expression - The Find text will be interpreted as a regular expression. There are various RegEx options;
  • No Options - Switch off all selected regular expression options.
  • Culture Invariant - Specifies that cultural differences in language is ignored.
  • Explicit Capture - Specifies that the only valid captures are explicitly named or numbered.
  • ^$ Matches Inline \n - Changes the meaning of ^ and $ so that they match at the beginning and end, respectively of any line, not just the beginning/end of the whole file or string.
  • . Matches \n - Specifies single-line mode. Changes the meaning of the period character (.) so that it matches every character (instead of every character except \n).
  • Compiled - Specifies that the regular expression will be compiled to an assembly. Generates MSIL code for the regular expression; this results in faster execution at the expense of startup time.
  • Right To Left - Specifies that the search moves from right to left instead of from left to right. (The starting position should be specified as the end of the string instead of the beginning).
  • Ignore Case - Specifies case-insensitive matching.
  • Ignore Pattern Whitespace - Specifies that unescaped white space is excluded from the pattern and enables comments following a number sign (#).
Use Pair List - This sets Batch-List mode.

Check for Updates - This invokes the MultiSub Updater and allows the user to check whether the installed version is up to date versus the web site. Depending on the nature of any available updates, the user can choose to install the update automatically, download the installer or visit the download page. MultiSub will contact dogsbyte.com and the user may see some warnings from any anti-virus or firewall software that may be installed. The MultiSub Updater only communicates with dogsbyte.com.




Settings Settings

MultiSub has a SettingsTab which has a number of preference controls.

ForeColor/BackColor/Font - These buttons open a color or font dialog box which allows the text color (ForeColor) and pane background color (BackColor) to be changed. Different users may find different colors easier to see, so this can be controlled. The font button allows the font and font size to be selected. Users with impaired vision may prefer slightly larger text. A PreviewPane is shown in the pane to the right of the Color/Font buttons.

TextColor/BackColor/Font - These buttons are similar to the previous, but set the text color and fonts for highlight text.

Use NotePad/Use WordPad - Select preferred editor when viewing the log file.

Pair File Delimiter - Selects the preferred delimiter character used in a batch list file containing find/replace pairs. The default is a comma (,).

Create Backups - When selected, MultiSub will make backups of the files that appear in the file list before each Replace operation. A folder called MultiSub.Backup.<TimeStamp> is created in the same location as the files in the file list. If Sub-folders is selected, a corresponding backup folder is created in each sub-folder. The folder name has a TimeStamp appended, this is simply the Date and Time. The name of the latest backup folder is shown at the bottom left of the MultiSubTab, it is also shown on the ResultsTab. To roll back to a previous version of the users files, the files should be copied out of each relevant backup folder and pasted into the folder above it.

Wrap Panes - This option sets the text display in the various panes to 'wrap'. This only affects how a file is displayed, it does not alter the file.

Turn off tool tips? - This turns off the helper (or hover) boxes that appear over controls when the mouse is stationary.

When inserting a newline use - When inserting text, MultiSub has the option to include an additional newline character to separate the find and replace text. By default this character is actually two characters; a Carriage Return (CR) and a Line Feed (LF). This is the standard newline character(s) for Windows. If you use a Unix or a Linux system, you may wish to use a solitary newline character, this can be chosen using the three buttons.

When writing Unicode use - MultiSub will write an input file out using the same encoding as the original file. When writing Unicode the standard end of line terminator is a LF. (Such files can be correctly viewed in Wordpad, but the line terminations will not be recognized by Notepad). However, this settings allows the user to specify that the file be written using the windows line terminator combination of CR/LF. The latter is the MultiSub default.




HTML Include
Using Multi-Sub to provide the capability to include files in HTML

HTML has no 'include' function. If there is for instance, a section of code common to many HTML files (it may be a menu, a table, a script, an advert etc.), it is very tedious to replace this text manually.

MultiSub can substitute text where both the Find text and Replace text can be the content of two files. So by copying the target text from an HTML file into a separate file (which becomes the Find file), putting the replacement text into another file (which becomes the Replace file), MultiSub can then do all of the substitutions in hundreds of files very quickly. This is a simple way of doing a mass replacement.

With a little thought, however, this process can be made more elegant. If there are sections of code within the HTML files which may change regularly, these can be replaced in such a manner that subsequent replacement is made much easier.

Within HTML, comment text can be denoted by placing "<!--" before it and by terminating the comment text with "-->". When the target text is substituted the first time, it is easy to prepend <!--MyFindFile1 Start--> to the beginning and append <--MyFindFile1 End--> to the end.

For example, consider a fragment of HTML as follows;


<b>This is my text which is ok</b>
But here is some text that may change quite often, like
a script, an advert, a menu of something like
that.
<b>This text is ok and needs to be kept</b>


Using MultiSub the Find file can be;

But here is some text that may change quite often, like
a script, an advert, a menu of something like
that.


The Replace file can be;

THIS IS MY NEW TEXT
THAT I WANT


The result being;

<b>This is my text which is ok</b>
THIS IS MY NEW TEXT
THAT I WANT
<b>This text is ok and needs to be kept</b>


To make this more elegant however, it would be neater to do this;

The Replace file can be;

<!--MyFindFile1 Start-->
THIS IS MY NEW TEXT
THAT I WANT
<!--MyFindFile1 End-->


Giving the result;

<b>This is my text which is ok</b>
<!--MyFindFile1 Start-->
THIS IS MY NEW TEXT
THAT I WANT
<!--MyFindFile1 End-->
<b>This text is ok and needs to be kept</b>


For any subsequent modification, we can use a RegEx as the Find expression and a Replace file with the replacement text. The replacement text would include the <!--MyFindFile1 Start--> and <!--MyFindFile1 End--> markers.

So next time around we can use a RegEx of;


<!--MyFindFile1 Start-->.*?<!--MyFindFile1 End-->

with RegEx option ". Matches \n" set. This Regex will select the start/end marker and any intervening text, even if the text straddles multiple lines.

Neat?, well do not forget that the marker can include the name of the Replace file. So we can be sure that there will be no unintended substitutions.

The only thing to ensure is that the first time the replacements are done (when inserting the markers) that this substitution is done properly within all files, after that there is no problem.







Back to top