Sample Applications
Perform Simple File Search
Search For Text In Files
Search For Text In Files In Multiple Folders
Search For Text Using Regular Expressions
Search And Replace Text In Files
Find and Replace Text in Word and Excel Files
Create a CSV File With E-mails Collected From Multiple Files
Insert A File Reference Regarding Directory Hierarchy
Grep http and ftp addresses (URL matching)
Perform Simple File Search
Text Workbench allows to perform simple file searches. To find find file(s) of any type, do the following.
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles\Projects
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp
- Empty the Find What field. This is important to just find
files, not text.
- Click the Search button.
Search For Text In Files
To find file(s) of the required type containing the specific text, do the following.
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles\Projects
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp
- Type the text that you want to find in the Find What field.
- Click the Search button. This is important to click this button
rather than Replace, to not replace occurrences of the found text.
Search For Text In Files In Multiple Folders | top |
To find file(s) of the required type containing the specific text in more than one folder, do the following.
- Specify the folders in which you want to find files. Separate multiple
folders with semicolon. For example:
C:\MyWebFiles\Projects;C:\MyProjects\CPP;C:\MyBooks\Programming
Alternatively,
you can use the Folder Manager
to specify multiple folders.
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp;*.cpp
- Type the text that you want to find in the Find What field.
- Click the Search button. This is important to click this button
rather than Replace, to not replace occurrences of the found text.
Search For Text Using Regular Expressions | top |
To find file(s) of the required type containing the text that matches a
pattern, do the following.
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles\Projects
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp;*.cpp
- Provide the pattern in the Find What field for the matching text that
you want to find.
For example, you want to find HTML files containing the
<OBJECT> tags, not simply word OBJECT. The corresponding
pattern would include:
- the opening tag;
- tag name (OBJECT);
- as the tag may contain attributes, some wildcard operator and repetition
operator that would match the remaining tag inner text;
- the closing tag.
The pattern in this case would look as follows:
\<OBJECT.#\>
- Click the Search button. This is important to click this button
rather than Replace, to not replace occurrences of the found text.
Search And Replace Text In Files | top |
To find file(s) of the required type and replace some text in them, do the
following.
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles\Projects
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp;*.cpp
- Type in the text that you want to find in the Find What field.
- Enter the text that you want to replace the found text in the Replace
With field.
- If you want to see what you will replace, click the Search button
before performing the actual replace.
- Make sure the option Search only is unchecked.
- Click the Replace button.
Find and Replace Text in Word and Excel Files | top |
To find the Microsoft Office file(s) of the required type and replace text in them, do the following.
- Specify the folder in which you want to find files. For example:
C:\MyOfficeFiles
- Set mask(s) of the files that you want to find.
- To search for the native Microsoft Word files (
.doc),
set the filter to *.doc.
- To search for
.rtf files to be processed with Microsoft
Word, set the filter to *.rtf.
- To search for both
.doc and .rtf files to be
processed with Microsoft Word, set the filter to
*.rtf;*.doc.
- To search for Microsoft Excel files (
.xls), set the
filter to *.xls.
- If you need to process both Microsoft Excel and Microsoft Word
files, set the filter to
*.rtf;*.doc;*.xls.
- Type in the text that you want to find in the Find What field.
- Enter the text that you want to replace the found text in the Replace
With field.
- The Microsoft Office searches allows using the Case-sensitive
search. If you need to find text exactly as you have typed, check this
option.
IMPORTANT! Make sure the options that allow
utilizing Microsoft Office facilities are on. To enable the processing, click
the Options button, go to the Processing tab and check options
Process .doc and .rtf files in Microsoft Word and/or Process .xls
files in Microsoft Excel. If these options are inactive, the safety filter
will reject such files (except .rtf because in fact they are text
files) and will not allow processing them.
- Make sure the option Search only is unchecked.
- Click the Replace button.
To simply search for files containing the text without modifying them, click the Search button.
Create a CSV File With E-mails Collected From Multiple Files | top |
We shall consider two examples of creating a CSV file - a simple one, just e-mails, and the one a bit more complex - collecting e-mails and names.
Collecting E-mails Only
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles
- Set mask(s) of the files that you want to find. For example:
*.htm*
- Switch on the regular expressions.
- As we need e-mails only, we won't bother matching the A tags. The expression would look like follows:
[\w\.\_\d]+\@[\w\.\_\d]+\.\w+
where [\w\.\_\d]+ matches all letters, dots, underscores and digits.
- Go to the Collect tab and check the Collect... option. Set the
path to the collector file, for example:
C:\MyWebFiles\emails.csv.
Set the Collected text to Found text, and Text entry
separator to New line.
- Click the Search button.
Collecting E-mails and the Anchored Text (usually a contact person name)
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles
- Set mask(s) of the files that you want to find. For example:
*.htm*
- Switch on the regular expressions.
- In this case, we have to match the A tags. The expression would look like follows:
\<a[^\>\<]#href\=\"mailto\:([\w\.\_\d\@]+)\"[^\>\<]@\>([^\<]#)\<\/a\>
where
[^\>\<]# matches all extra information
between the tag name and HREF attribute;
([\w\.\_\d\@]+) matches and stores the e-mail address
(first stored expression);
([^\<]#) matches and stores the tag inner text
(second stored expression).
- We will have to reformat the stored expressions to match the CSV format.
Please note that we can still use the replacement strings for collecting even if
searching. So, in the Replace with field we shall type:
\2,\1
where \2 is the stored inner text of a tag (contact person title). \1 is the stored e-mail address.
- Go to the Collect tab and check the Collect... option.
- Set the path to the collector file, for example:
C:\MyWebFiles\emails.csv.
- Set the Collected text to Replacement text, and Text entry
separator to New line.
- Click the Search button.
Insert A File Reference Regarding Directory Hierarchy | top |
To insert a reference to a file regarding the directory structure, do the
following.
The Problem
You have to add a reference to a CSS file style.css stored in the folder C:\MyWeb\HTML to all your HTML pages, stored in different folders starting from C:\MyWeb\HTML.
The Solution
- Specify the folder in which you want to find files. For example:
C:\MyWeb\HTML
- Set mask(s) of the files that you want to find. For example:
*.htm*
- We will insert a LINK tag right after the HEAD tag. So, we shall provide the following pattern in the Find What field:
\<HEAD\>
- Provide the replacement expression:
\0\r\n<LINK REL=stylesheet
HREF=\"\Ph:"C:\\MyWeb\\HTML\\style.css"\" TYPE="text/css">
where
\0 is the found text (<HEAD>);
\Ph:"C:\\MyW..." executes the path resolve operator,
telling to use the HTML mode (h letter)
- Make sure the option Search only is unchecked.
- Click the Replace button.
The Result
This will insert the following text in HTML files in, say, C:\MyWeb\HTML\Catalog:
<LINK REL=stylesheet HREF="../style.css" TYPE="text/css">
and the following text in HTML files in C:\MyWeb\HTML\Catalog\dir1\dir2:
<LINK REL=stylesheet HREF="../../../style.css" TYPE="text/css">
Note! Root parts of path names of both a referenced and
processed file must be the same. It means that they must have a common drive
letter.
Grep http and ftp addresses (URL matching) | top |
This is an answer to the question that a user asked once.
The Problem
"I want to "grep" http, and ftp, address' from newsgroup posts that I have kept BUT I cannot work out how it can be done with your program. I once tried a grep utility that seemed to do it but I have forgotten how I did things."
The Solution
You can notice that an URL in your case starts with ftp:// or http:// or www. We can distinct such URL's from common text by the suffix: :// for protocols and the dot . for domain (www). Then, first part of an URL may contain digits, letters, dots, underscores, dashes. Thus, the pattern that would match your example would be:
{{http}|{ftp}\:\/\/}|{www\.}[\d\w\_\.\-]+{\/\S+}?
where {\/\S+}? means matching the relative part of an URL, for example /dir/file.ext in http://dom.com/dir/file.ext. This allows to find any URL's, with or without file names.
Download Free Trial Order Full version
|