replace blocks of text

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

shveicar980
Posts: 11
Joined: Thu Apr 26, 2012 11:57 pm

replace blocks of text

Postby shveicar980 » Thu May 03, 2012 3:15 am

Hello
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

A-Z....A-Z1
A-Z....A-Z2
A-Z....A-Z3

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.

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: replace blocks of text

Postby DataMystic Support » Thu May 03, 2012 10:43 am

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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

shveicar980
Posts: 11
Joined: Thu Apr 26, 2012 11:57 pm

Re: replace blocks of text

Postby shveicar980 » Fri May 04, 2012 12:43 am

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)
 else
 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?

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: replace blocks of text

Postby DataMystic Support » Wed May 09, 2012 4:42 pm

The attached script replaces title tags with text from the file c:\replaces.txt
This file has one replacement per line.
Attachments
different replace each time from file.zip
(1.06 KiB) Downloaded 332 times
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: replace blocks of text

Postby gerd » Thu May 17, 2012 12:26 am

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.
field1,field2,filename1.txt,field4

Thanks
gerd

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: replace blocks of text

Postby DataMystic Support » Thu May 17, 2012 8:28 am

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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: replace blocks of text

Postby gerd » Mon May 21, 2012 9:14 pm

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

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: replace blocks of text

Postby DataMystic Support » Tue May 22, 2012 10:27 am

Ah - my mistake. Please find updated code attached.
Attachments
different replace each time from file.zip
(1.06 KiB) Downloaded 329 times
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: replace blocks of text

Postby gerd » Tue May 22, 2012 4:58 pm

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

gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: replace blocks of text

Postby gerd » Tue May 29, 2012 4:01 am

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

David_Johnson
Posts: 3
Joined: Wed May 30, 2012 2:09 am

Re: replace blocks of text

Postby David_Johnson » Wed May 30, 2012 2:23 am

Hello Gerd

I am taking a look at this today.

Regards
David

David_Johnson
Posts: 3
Joined: Wed May 30, 2012 2:09 am

Re: replace blocks of text

Postby David_Johnson » Wed May 30, 2012 3:41 am

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.
Attachments
gerd.zip
(3.33 KiB) Downloaded 364 times

David_Johnson
Posts: 3
Joined: Wed May 30, 2012 2:09 am

Re: replace blocks of text

Postby David_Johnson » Wed May 30, 2012 3:54 am

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.


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 1 guest