topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 2:52 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: A Search and Replace Utility to increment range of numbers in a text file ?  (Read 5796 times)

patteo

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 437
    • View Profile
    • Read more about this member.
    • Donate to Member
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

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Hm, it sounds like something that would be very simple to do with a scripting language that supports regular expressions. PERL, anyone? :)
- carpe noctem

Veign

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 993
    • View Profile
    • Veign - Where design meets development
    • Donate to Member
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

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
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...
- carpe noctem

Veign

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 993
    • View Profile
    • Veign - Where design meets development
    • Donate to Member
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.