I have multiple hits of number 45371001190000 in the text document so for each hit i want to increase the number by 1 for example for first hit no change to 45371001190000 for 2nd hit it should be updated to 45371001190001 and for the next 45371001190002 and so on .
Thanks to advance for the help,
]]>But I just realize that, in case the 45371001190000 number is not on consecutive lines
I’m glad you realized that…
Of course this short Python
script is ridiculously easy to understand ;-))
With regular expressions, it’s a little longer but still doable !
For instance, given the sample text :
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
The number 45371001190000 is increasing...
With this fist regex S/R, we add the left part of the number, at beginning of lines, followed with a space character :
SEARCH ^
REPLACE 4537100\x20
giving :
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
4537100 The number 45371001190000 is increasing...
Now, place the caret, on the 1st
line, right after the number 4537100
Select the option Edit > Column Editor...
( Alt + C
)
Choose the option Number to Insert
Type in 1190000
in field Initial number
Type in 1
in field Increase by
Type in 1
in field Repeat
Select, if necessary, the Dec
format
Click on the OK
button
We get :
45371001190000 The number 45371001190000 is increasing...
45371001190001 The number 45371001190000 is increasing...
45371001190002 The number 45371001190000 is increasing...
45371001190003 The number 45371001190000 is increasing...
45371001190004 The number 45371001190000 is increasing...
45371001190005 The number 45371001190000 is increasing...
45371001190006 The number 45371001190000 is increasing...
45371001190007 The number 45371001190000 is increasing...
45371001190008 The number 45371001190000 is increasing...
45371001190009 The number 45371001190000 is increasing...
45371001190010 The number 45371001190000 is increasing...
45371001190011 The number 45371001190000 is increasing...
45371001190012 The number 45371001190000 is increasing...
45371001190013 The number 45371001190000 is increasing...
45371001190014 The number 45371001190000 is increasing...
45371001190015 The number 45371001190000 is increasing...
45371001190016 The number 45371001190000 is increasing...
45371001190017 The number 45371001190000 is increasing...
45371001190018 The number 45371001190000 is increasing...
45371001190019 The number 45371001190000 is increasing...
Finally, the regex S/R, below, overwrites the 45371001190000
number with the increasing number, at present start of lines
SEARCH (?-s)^(\d+)(.+?)45371001190000
REPLACE \2\1
The number 45371001190000 is increasing...
The number 45371001190001 is increasing...
The number 45371001190002 is increasing...
The number 45371001190003 is increasing...
The number 45371001190004 is increasing...
The number 45371001190005 is increasing...
The number 45371001190006 is increasing...
The number 45371001190007 is increasing...
The number 45371001190008 is increasing...
The number 45371001190009 is increasing...
The number 45371001190010 is increasing...
The number 45371001190011 is increasing...
The number 45371001190012 is increasing...
The number 45371001190013 is increasing...
The number 45371001190014 is increasing...
The number 45371001190015 is increasing...
The number 45371001190016 is increasing...
The number 45371001190017 is increasing...
The number 45371001190018 is increasing...
The number 45371001190019 is increasing...
Of course, just an exercise…, ah ah !
But I just realize that, in case the 45371001190000
number is not on consecutive lines, the Column Editor method does not work. Indeed, the script method is the definitive one ;-))
Best Regards
guy038
]]>Sure. There’s already a great example for Pythonscript that is close to what you want to do:
In the help file for editor.rereplace
:
def add_1(m):
return 'Y' + str(number(m.group(1)) + 1)
# replace X followed by numbers by an incremented number
# e.g. X56 X39 X999
# becomes
# Y57 Y40 Y1000
editor.rereplace('X([0-9]+)', add_1);```
]]>You need a programming language to help with this, I’m afraid. You could certainly use a scripting plugin for Notepad++ as that programming language…
]]>