Search and replace with incremental numbers

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
garywiscombe
Posts: 1
Joined: Sat May 10, 2008 10:33 pm

Search and replace with incremental numbers

Post by garywiscombe »

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
User avatar
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

Post by DataMystic Support »

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:

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
Evgeny
Posts: 1
Joined: Thu Feb 16, 2012 4:52 pm

Re: Search and replace with incremental numbers

Post by Evgeny »

Hi!
a line counter that does not reset for each file
How to reset a line counter for each file?
User avatar
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

Post by DataMystic Support »

The script above does reset for each file.

Please explain where you grabbed that quote from - I suspect your comment is spam.
Post Reply