Page 1 of 1

replace blocks of text

Posted: Thu May 03, 2012 3:15 am
by shveicar980
Can I use the program textpipe
carry out multiple pieces of text substitution between the html tags such as
<title> replacement text is different in each html file </ title>
Information that is changing the text is taken from a separate file (for example filelist.txt)
and placed on a file filelist.txt line.
(long block of text up to 250 characters is a division of New Line)

Code: Select all

The replacement in the html files will be made in order.

Code: Select all

A-Z..1.html <-> A-Z....A-Z1
A-Z..2.html <-> A-Z....A-Z2
A-Z..3.html <-> A-Z....A-Z3
If this is possible, how to do it.
I look forward to your help. Thanks.

Re: replace blocks of text

Posted: Thu May 03, 2012 10:43 am
by DataMystic Support
Yes - there is a sample filter called
\script filter\control replacements
which gets you most of the way there.

The trick is to load the replace list file in the vbscript, then iterate through this file with each search replace term.

Let me know if you need more help with that.

Re: replace blocks of text

Posted: Fri May 04, 2012 12:43 am
by shveicar980
Thanks for your help
I have downloaded from your site filter control replacements.fll
It consists of a single filter and two subfilters.
As I understood I will need to load the contents of a text file, for example:

Code: Select all

page number 1
page number 2
page number 3
and load in the second post filter - filter vbs
its contents

Code: Select all

'Count the replacements

 dim a

 function processLine(line, EOL)
 a = a + 1
 if a mod 2 = 0 then
 processLine = TextPipe.subFilterEntireText(line & EOL)
 processLine = line & EOL
 end if
 end function

 sub startJob()
 a = 0
 end sub

 sub endJob()
 end sub

 function startFile()
 startFile = ""
 end function

 function endFile()
 endFile = ""
 end function
1.Where do I need to add these lines?
2.What should I do with the first and third filters (disable, modify, or delete)?
3. Will I add 3 html file in the Filles to process and to begin treatment after all the changes with the filters?

Re: replace blocks of text

Posted: Wed May 09, 2012 4:42 pm
by DataMystic Support
The attached script replaces title tags with text from the file c:\replaces.txt
This file has one replacement per line.

Re: replace blocks of text

Posted: Thu May 17, 2012 12:26 am
by gerd
Hi Simon,
could you please give an example of the contents of the replacement file "replaces.txt".
Assuming as in the example the contents of the title tag should be changed. This is the file replaces.txt

"C:\Program Files\TextPipe\files\78751.htm",this is new title 1
"C:\Program Files\TextPipe\files\78752.htm",this is new title 2
"C:\Program Files\TextPipe\files\78753.htm",this is new title 3

As you see the file 78751.htm should get as title text: this is new title 1

I do not understand the meanĂ­ng in the Trial Area, e.g.


Re: replace blocks of text

Posted: Thu May 17, 2012 8:28 am
by DataMystic Support
Hi Gerd,

The replacement file "replaces.txt" should look like this:

Code: Select all

title for file1
title for file2
title for file3
title for file4
title for file5
The contents of the Trial Run area don't sound appropriate for testing.

It looks like you need a filename -> new title mapping. Can you work with what is above? You need to add files to the files list in the right order. You can extract column 1 from your list and load this as a text file.

Re: replace blocks of text

Posted: Mon May 21, 2012 9:14 pm
by gerd
I get the following error translated into Englilsh

[424] runtime error in Microsoft VBScript:Object 'objTextFile' at line 30, char:2near:
object required:'objTextFile'

Since I did not change anything in the VB Script it seems to me that the script itself requires an adjustment.

The production of the mapping filenames --> replacementts ist not a problem. The problem is the error message.
Line 30 reads as follows:
Do Until objTextFile.AtEndOfStream

thanks gerd

Re: replace blocks of text

Posted: Tue May 22, 2012 10:27 am
by DataMystic Support
Ah - my mistake. Please find updated code attached.

Re: replace blocks of text

Posted: Tue May 22, 2012 4:58 pm
by gerd
I get now a different error mesage.

[13] Runtime error in Microsoft VBScript: Typ 'UBound' at line:32,char:4near;

Line 32 reads as follows:
ReDim Preserve fileContents(UBound(fileContents) + 1)

I have TP Pro 9.1. Could you please check again wotj TP Pro 9.1. Such a filter would be pretty useful since users could take a filenames.txt and a replaces.txt to perform different replacements. To arrange for the order in the .txt files is not a problem.
thanks gerd

Re: replace blocks of text

Posted: Tue May 29, 2012 4:01 am
by gerd
Excuse me for bringung up the point again.

But I have a strong demand for a working VB script to replace a string on a line-by-line basis as described below. Example: filelist.txt with 20 lines (filenames) and a file replaces.txt with 20 lines of different replacements. If anyone could help to make it happen I would be glad to send him or her an amazon gift certificate of 50 Euro. I assume this could help quite a few users.
Thanks gerd

Re: replace blocks of text

Posted: Wed May 30, 2012 2:23 am
by David_Johnson
Hello Gerd

I am taking a look at this today.


Re: replace blocks of text

Posted: Wed May 30, 2012 3:41 am
by David_Johnson
I think this is what you needed; see attached.

It expects a replacement file with filenames and replacement strings, separated by tabs.

Filenames can be with or without full path:
* C:\Users\David\Dropbox\Private\work\datamystic\gerd.txt
* or gerd.txt

You will need to update the location of this file in the VBScript source, as documented.

Let me know if this works for you.

PS - We can arrange the amazon thing offline.

Re: replace blocks of text

Posted: Wed May 30, 2012 3:54 am
by David_Johnson
I just re-read your request and see that you had originally requested that the filenames be in one file and the replacements in another. I put them into a single file, separated by tabs. If this is not acceptable, it is a small change to make it read 2 files as you originally requested.