how to increment a number in a file

Help with writing and running scripts

how to increment a number in a file

Postby ftpaccess » Wed Sep 22, 2010 7:23 am

I have this code multiple times in a file

Code: Select all
TAB T=1     
TAG POS=57 TYPE=A ATTR=TXT:info   
'New page loaded     
TAB T=2     
TAG POS=1 TYPE=H2 ATTR=TXT:* EXTRACT=TXT 
TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT 
TAG POS=1 TYPE=BODY ATTR=TXT:* EXTRACT=TXT 
TAB CLOSE     
SAVEAS TYPE=EXTRACT FOLDER=* FILE=*

Now I want to increase TAG POS=57 to TAG POS=58, 59, 60 and so on. What can I use in this case?
ftpaccess
Newbie
 
Posts: 7
Joined: Fri Apr 30, 2010 12:38 am

Re: how to increment a number in a file

Postby Mofi » Wed Sep 22, 2010 10:52 am

A small script is used best, for example below starting the count with 1.

Code: Select all
if( UltraEdit.document.length ) {
   UltraEdit.activeDocument.top();
   UltraEdit.ueReOn();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchAscii=false;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=false;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   var nTagPos = 1;
   while( UltraEdit.activeDocument.findReplace.replace("TAG POS=[0-9]+", "TAG POS="+nTagPos.toString())) nTagPos++;
   UltraEdit.activeDocument.top();
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts