Replace text with incremented counter?
-
Newbie here - please be gentle! :)
I’m sure there must already be a way to do this, but I haven’t yet figured it out. I’m trying to find a way to replace text with an incremented counter. For example, if I have a file containing this:
= = = = = = = = = =
Lorem ipsum dolor sit amet, 9999, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 9999, exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in 9999, voluptate
= = = = = = = = = =I’d like to replace the first occurrence of “9999” with “1”, the second occurrence of “9999” with “2”, etc., resulting in:
= = = = = = = = = =
Lorem ipsum dolor sit amet, 1, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 2, exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in 3, voluptate
= = = = = = = = = =I don’t see any way to do this through regular expressions. I’m guessing it might be possible with TextFX, but I’m apparently too stupid to figure out how. Is there a way to do this with Notepad++?
-
I don’t think you can do it with regular expressions, but @guy038 has done some amazing things with them, so it might be possible.
You can do this easily using some scripting language like AWK, PERL, or Python.
If you (and by you I mean anyone reading this) are a coder, or if you often work with and have to manipulate text files, you really should take the time to get familiar with some scripting language–it will save you loads of time in the long run.
-
PHP.
One of my friends make a script for me, with increment and replace. Put this php file from the .zip in localhost (with the files that you want to change). Change “wxyz” with the word you want to make the increment. Then run the replace+increment.php
All your files will be change in a second with increment.
It is easy.
http://www.mediafire.com/download/fpcmqerrn0eccvz/replace+increment.zip
-
Hello beerslayer, Jim and Vasile Caraus,
Jim, many thanks for your judgement about my work on regexes ! But, unfortunately, as you said, this kind of replacement needs a script or programming language !
In addition, to the Vasile Caraus’s solution, I (re-) found out a post of Dave Brotherstone ( the author of the excellent N++ Python script ), on SourceForge.net, related to that topic. So, beerslayer, just refers to the link below :
https://sourceforge.net/p/npppythonscript/discussion/1199074/thread/8d2ed95a/?limit=25#628b
Have also a look to a Claudia Franck’s solution, on our site :
Best Regards,
guy038
-
Im typing from mobilr so excuse my typod if any…
Mark the column you want to replcae with block sekection -mouse and alt - then menues! Edit! Column editor…
You can figure it out from there -
I don’t think “typing from your mobile” excuses you from typos, inaccuracies, or whatever it is you think it excuses you from…if you are going to post, you bear the responsibility for correcting (most…[nobody is perfect!]) typos before submitting, or you won’t be taken seriously here. Typos aside, you also should have a quality answer, if your post is providing a solution to a question, and you do not have that either, sorry.
-
I use note pad for script proseccing so im just assuming that 9999 has fixed position in all lines,this is typical case of mine, if this is not the case then just ignore my initative to be helpful. you dont have to be rude…
-
@beerslayer You can do this using a Regular Expression but not in Notepad++
TextPad has a built in function that uses /i for increment
https://textpad.com/download/index.htmlFind: ^\r\n(.*\r\n)
Replace: \r\n\i $1 -
Starting to wonder if this isn’t spam for TextPad as you posted virtually the same thing in THIS THREAD that has an extremely similar title.
If it is NOT spam, then what is the point of posting it here?