I have a large txt file with numerous occurences of the text block "XXXX". I would like TextPipe to search for these occurences and replace the text block "XXXX" with a sequential number 0001, 0002, 0003 etc...
Is this possible?
Thanks Gary
Search and replace with incremental numbers
Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators
-
- Posts: 1
- Joined: Sat May 10, 2008 10:33 pm
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: Search and replace with incremental numbers
Sure Gary,
With TextPipe Pro, use a search/replace for XXXX, the replacement doesn't matter.
Now add a Filters\Special\Script (VBScript,JScript...) filter, and drag it as a subfilter of the search/replace.
Replace the sample code with this code:
With TextPipe Pro, use a search/replace for XXXX, the replacement doesn't matter.
Now add a Filters\Special\Script (VBScript,JScript...) filter, and drag it as a subfilter of the search/replace.
Replace the sample code with this code:
Code: Select all
'This example script keeps a line counter that
'does not reset for each file
'Our line counter
dim a
'Called for every line in the file
'EOL contains the end of line characters (Unix, DOS or Mac) that must be
'appended to each line
function processLine(line, EOL)
'insert the count
processLine = a
end function
'Called at the start of a processing job -
'perform one-time initialisation here
sub startJob()
a = 0
end sub
'Called at the end of a processing job -
'destroy any declared objects here
sub endJob()
'do nothing
end sub
'Called before each file is opened -
'perform per-file initialisation here
function startFile()
a = 0
startFile = ""
end function
'Called before each file is closed -
'flush all pending file output here
function endFile()
endFile = ""
end function
Re: Search and replace with incremental numbers
Hi!
How to reset a line counter for each file?a line counter that does not reset for each file
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: Search and replace with incremental numbers
The script above does reset for each file.
Please explain where you grabbed that quote from - I suspect your comment is spam.
Please explain where you grabbed that quote from - I suspect your comment is spam.