16

I've to add numbers incrementally in the beginning of every line using Notepad++. It is the not the very beginning. But, like

  when ID = '1' then data
  when ID = '2' then data
  when ID = '3' then data
  .
  .
  .
  .
  when ID = '700' then

Is there any way i can increment these numbers by replacing with any expression or is there any inbuilt-notepad functions to do so.

Thanks

YakovL
  • 7,557
  • 12
  • 62
  • 102
Rohin
  • 516
  • 3
  • 7
  • 20
  • 1
    it's not the job of a regex. – Avinash Raj Aug 21 '14 at 14:13
  • No, you can't do that with regex. – RevanProdigalKnight Aug 21 '14 at 14:13
  • you can write a perl script for it. – Jason Hu Aug 21 '14 at 14:18
  • is it. Just looking to reduce some pain in adding 700+ records. thank you anyway – Rohin Aug 21 '14 at 14:19
  • 1
    use python.open a file in write mode.then a simple loop. – vks Aug 21 '14 at 14:27
  • @rohin it needs a language. Which lang did you prefer? – Avinash Raj Aug 21 '14 at 14:28
  • @AvinashRaj I got a solution now. Check the answer. So, Please do avoid to say not possible in future and also bit of politeness will sound your capability further. I've read your deleted comment, which told me to delete my question after reading your first comment. It didn't bother me, because you are not the only one who knows the answer and in fact, i was awaiting a fitting answer to get back to you. Thanks anyway – Rohin Aug 21 '14 at 15:28
  • @rohin yep, i told you to delete this question because of the answer you accepted before. And my point is correct, regex isn't does this job, it was done by an inbuilt function in the tool notepad++ – Avinash Raj Aug 21 '14 at 15:33

3 Answers3

36

If you want to do this with notepad++ you can do it in the following way.

First you can write all the 700 lines with template text (you can use a Macro or use the Edit -> Column Editor). Once you have written it, put the cursor on the place you want the number, click Shift+Alt and select all the lines:

enter image description here

enter image description here enter image description here

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
1

It's not possible to accomplish this with a regular expression, as you will need to have a counter and make arithmetic operations (such as incrementing by one).

Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • 1
    You have marked this as answer?This didnt ans your question and also it was mentioned in comments before. – vks Aug 21 '14 at 14:29
  • @vks It actually answers the question, and I don't seem to find (in the comments) an **actual explanation** of ***why*** a Regex can't be used – Matias Cicero Aug 21 '14 at 14:30
  • cannot agree to this.It has not helped him neither anybody else.An ans like something in another language like perl or python would have been better for being marked as answer. – vks Aug 21 '14 at 14:35
  • 1
    @MatiCicero you could simply do this through awk. `awk '{print NR,$0}' file` – Avinash Raj Aug 21 '14 at 14:38
1

You can try the cc.p command of ConyEdit. It is a cross-editor plugin for the text editors, of course including Notepad++.

With ConyEdit running, copy the text and the command line below, then paste:

when ID = '#1' then data
cc.p 700

Gif example

Gif Example

rkta
  • 3,959
  • 7
  • 25
  • 37
Donald
  • 131
  • 1
  • 4