Main Area and Open Discussion > General Software Discussion
A Search and Replace Utility to increment range of numbers in a text file ?
(1/1)
patteo:
I'm looking for a Search and Replace Utility that can process and increase or decrease numbers in a simple text file that contains text such as :
<target="2"/>
<target="12"/>
<target="13"/>
<target="14"/>
<target="15"/>
<target="16"/>
<target="17"/>
<target="3"/>
<target="4"/>
2</PARA>
3</PARA>
4</PARA>
12</PARA>
13</PARA>
14</PARA>
15</PARA>
16</PARA>
17</PARA>
2
3
4
12
13
17
15
16
17
What it needs to do is to search through the file and increase or decrease only the numbers that is
preceeded by
<target=
and greater than or equal to say 13 by a definable number of say 2
Likewise it should be able to search through the file and incease or decrease also the numbers that is followed by
</PARA>
and greater than or equal to say 13 by a definable number of say 2
It should leave any other numbers it encounters alone.
End result should be
<target="2"/>
<target="12"/>
<target="15"/>
<target="16"/>
<target="17"/>
<target="18"/>
<target="19"/>
<target="3"/>
<target="4"/>
2</PARA>
3</PARA>
4</PARA>
12</PARA>
15</PARA>
16</PARA>
17</PARA>
18</PARA>
19</PARA>
2
3
4
12
13
17
15
16
17
I tried Replacem http://www.orbit.org/replace/ but it does not have a facility to increase or decrease numbers found it a search string.
Why I would find such a utility useful is that I have to change many more numbers and the process would be quite tedious.
If no such utility is available, can such a utility be written with the Autohotkey that so many are raving about.
f0dder:
Hm, it sounds like something that would be very simple to do with a scripting language that supports regular expressions. PERL, anyone? :)
Veign:
I am not too good with regular Expressions but my Seeker application supports them. Then you could check out one of the RegEx library sites / forums to see if this is possible with a single RegEx.
Regular Expression Library:
http://regexlib.com/default.aspx
Regular-Expressions.info:
http://www.regular-expressions.net/
Also, after using it if there are features you would like to see added just contact me directly - always looking to improve the application based on user feedback.
f0dder:
The substitution probably can't be done directly within a regexp, but regexp means you can identify the text to be substituted easily and safely, but without having to parse XML...
Veign:
I see what you are saying. RegEx doesn't provide a mechanism for incrementing a value it's replacing. I have used only simple regular expressions.
Thanx for clearing that up.
Navigation
[0] Message Index
Go to full version