Hello
I have a single HTML file and I would like to search for a value in that file, replace that value with the first line from a different text file, save the file with a new filename (the same as the value that I added) and then keep repeating this process through the subsequent lines in my text file.
So, for example I have original-file.html and a text file with value1, value2, value3, value4, etc each on a separate line. I need to create value1.html, value2,html, value3.html, value4.html and in each of those files I need to replace <span>original-file</span> with <span>value1</span>, <span>value2</span>, <span>value3</span>, <span>value4</span>
How do I do this in TextPipe?
Many thanks
Howard
Creating multiple files based on a list
Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: Creating multiple files based on a list
Since you can't change the output file yourself during a job, the best way is to automate TextPipe from a scripting language.
The script below gives the main structure, you just need to add code to load your list, and then run the filter once for each line in the file.
The script below gives the main structure, you just need to add code to load your list, and then run the filter once for each line in the file.
Code: Select all
dim f1
'The global TextPipe Application object
dim TextPipeApp
'The global TextPipe Filter Window
dim TPWindow
sub vb_connectTextPipe()
on error resume next
Set TextPipeApp = CreateObject("TextPipe.Application")
if Err.Number <> 0 then
MsgBox "TextPipe Pro is not installed." & vbCrLF & _
vbCrLf & _
"Please download and install it from" & vbCrLF & _
"http://www.datamystic.com", _
vbExclamation + vbOkOnly, _
"TextPipe Pro needs to be installed"
end if
Set TPWindow = TextPipeApp.newWindow
end sub
'disconnect from TextPipe
sub vb_disconnectTextPipe()
if isObject( TPWindow ) then
TPWindow.closeWithoutSave
Set TPWindow = Nothing
end if
if isObject( TextPipeApp ) then
Set TextPipeApp = Nothing
end if
end sub
vb_connectTextPipe
TPWindow.startFilters
TPWindow.clearAllFilters
TPWindow.logEnabled = false
TPWindow.logFilename = "textpipe.log"
TPWindow.logAppend = true
TPWindow.logThreshold = 500
TPWindow.inputMode = 1
TPWindow.inputBinaryFiles = 1
TPWindow.inputBinarySampleSize = 100
TPWindow.inputPromptOnEach = false
TPWindow.inputPromptOnReadOnly = false
TPWindow.inputDeleteFiles = false
TPWindow.inputInsideCompressed = false
f1 = TPWindow.addReplaceFilter( "your constant string", "variable string", 4, false, false, false, false, false, false, false, 0 )
f1 = TPWindow.setPerl( 4096, false, false, true, false )
TPWindow.outputMode = 2
TPWindow.outputMergeFile = "c:\variable string.txt"
TPWindow.endFilters
'File List:
TPWindow.clearAllFiles
TPWindow.addFile "", 0, 1
if TPWindow.execute = false then MsgBox "ERROR " & vbCrLF & TPWindow.errorText
vb_disconnectTextPipe