Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ incrementally replace

Lets say I want to have a 10 rows of data but I want a value to increment for each row or piece of data. How do I increment that value?

For example....If I have these rows, is there a regex way of replacing the id values to increment?

<row id="1" /> <row id="1" /> <row id="1" /> <row id="1" /> <row id="1" /> 

--- Here is what I would like it to look like... (if the first row's id goes up one thats ok)

<row id="1" /> <row id="2" /> <row id="3" /> <row id="4" /> <row id="5" /> 
like image 969
Travyguy9 Avatar asked Sep 29 '11 20:09

Travyguy9


People also ask

How do you use the Replace function in notepad?

Replacing text within NotepadOpen the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement.

How do I replace numbers in Notepad++?

"[0-9]+" will replace ANY NUMBERS!


2 Answers

Not sure about regex, but there is a way for you to do this in Notepad++, although it isn't very flexible.

In the example that you gave, hold Alt and select the column of numbers that you wish to change. Then go to Edit->Column Editor and select the Number to Insert radio button in the window that appears. Then specify your initial number and increment, and hit OK. It should write out the incremented numbers.

Note: this also works with the Multi-editing feature (selecting several locations while maintaining Ctrl key pressed).

This is, however, not anywhere near the flexibility that most people would find useful. Notepad++ is great, but if you want a truly powerful editor that can do things like this with ease, I'd say use Vim.

like image 97
voithos Avatar answered Sep 18 '22 13:09

voithos


I was looking for the same feature today but couldn't do this in Notepad++. However, we have TextPad to our rescue. It worked for me.

In TextPad's replace dialog, turn on regex; then you could try replacing

<row id="1"/> 

by

<row id="\i"/> 

Have a look at this link for further amazing replace features of TextPad - http://sublimetext.userecho.com/topic/106519-generate-a-sequence-of-numbers-increment-replace/

like image 37
Bipin Mangwani Avatar answered Sep 20 '22 13:09

Bipin Mangwani