Page 1 of 1
Can Textpad fill numbers?
Posted: Sat Nov 17, 2007 10:12 pm
by halfmile
I need to do a replace where I subtract 1 from a number (or start counting up from 0). I need to change this:
<name>RPT001</name>
<name>RPT002</name>
<name>RPT003</name>
<name>RPT004</name>
to this:
<name>H000</name>
<name>H001</name>
<name>H002</name>
<name>H003</name>
Is this possible with Textpad?
-H
Posted: Sun Nov 18, 2007 3:51 pm
by talleyrand
Textpad cannot do mathematics so the subtraction is out. However, it can do a count of replacements done with \i so in your example you would need to do a special case of inserting the 0s and then for 1-X use a replacement such as
h\i
Now, that won't fill out the leading zeros but I'm sure ben or someone else whose brain is far more perky this morning will point out what I'm missing.
You might also check the fill block option, that can do range as well.
Posted: Sun Nov 18, 2007 6:10 pm
by Bob Hansen
You can fill with the numbers.
Configure/Word Wrap Off and Block Select Mode
Select the columns you want to fill, replacing the existing numbers.
Choose Edit/ Fill Block/
Select Fill With Numbers vs. characters
Enter number range from 0, increment by 1
Select format for Leading zeros
Choose Fill Mode of Replace,
And you can do a normal Replace "RPT" with "H"
If done wrong, you can always do CTL-Z to undo and try again.
--------------
PS, as moderator, I changed your Subject to be more meaningful.
Posted: Fri Nov 30, 2007 4:24 am
by peterl
Grab youself perl from
http://www.activestate.com/solutions/perl/
Then try this:
Code: Select all
type originalfile.txt | perl -ne "s/RPT(\d{3})/sprintf('H%03i',$1-1)/e;print" > newfile
Peter