Search and replace with incremental numbers

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

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

Search and replace with incremental numbers

Postby garywiscombe » Sat May 10, 2008 10:38 pm

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: 2136
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Search and replace with incremental numbers

Postby DataMystic Support » Thu May 15, 2008 1:42 pm

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

Evgeny
Posts: 1
Joined: Thu Feb 16, 2012 4:52 pm

Re: Search and replace with incremental numbers

Postby Evgeny » Thu Feb 16, 2012 5:03 pm

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: 2136
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Search and replace with incremental numbers

Postby DataMystic Support » Thu Feb 16, 2012 7:29 pm

The script above does reset for each file.

Please explain where you grabbed that quote from - I suspect your comment is spam.
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


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

Who is online

Users browsing this forum: No registered users and 1 guest