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
Can Textpad fill numbers?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
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.
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.
I choose to fight with a sack of angry cats.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
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.
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.
Hope this was helpful.............good luck,
Bob
Bob
Grab youself perl from http://www.activestate.com/solutions/perl/
Then try this:
Peter
Then try this:
Code: Select all
type originalfile.txt | perl -ne "s/RPT(\d{3})/sprintf('H%03i',$1-1)/e;print" > newfile