3

Hello i got something in format:

Marcin:Marcin
Pawel:Pawel

i want to add numbers between 0-99 at the end of line so result should be like:

Marcin:Marcin1
Marcin:Marcin2
..
Marcin:Marcin99
Pawel:Pawel1
Pawel:Pawel45
..
Pawel:Pawel99

etc.

Does there exist any command or plugin what can do it?

I tried manually but its so waste time, also i tried find it on google but no results.

3 Answers3

1

You can run a python script within the PythonScript plugin.

If it is not yet installed, follow this guide

  • Create a script (Plugins >> PythonScript >> New Script)
  • Copy this code and save the file (for example insert_num.py):
import re

def insert_num(match):
    strout = ''
    maxcount = 100
    for counter in range(1, maxcount):
        strout += match.group() + str(counter)
        if counter < maxcount - 1:
            strout += "\n"
    return strout
    
editor.rereplace(r'^.+(?<!\d)$', insert_num)
  • Open the file you want to modify
  • Run the script (Plugins >> PythonScript >> Scripts >> insert_num)
  • Done

Result for given example: (shortened)

enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
0

Here is a JavaScript macro for EmEditor to add numbers from 1-99 at the end of all lines.

Redraw = false;
nLines = document.GetLines();
arr = new Array();
for( i = 0; i < nLines; ++i ) {
    arr[i] = document.GetLine( i + 1 );
}
document.selection.SelectAll();
document.selection.Delete();
for( i = 0; i < nLines; ++i ) {
    if( arr[i].length != 0 ) {
        document.Numbering( arr[i] + "1","1",99,0);
    }
}

To run this, save this code as, for instance, Macro.jsee, and then select this file from Select... in the Macros menu. Finally, select Run Macro.jsee in the Macros menu while the document you want to edit is active.

Yutaka
  • 1,761
  • 2
  • 5
  • 9
  • 1
    its another way to do it? i got like 1k lines and i would like to add them all numbers between 0-99 – Marcin Tomczak Dec 14 '22 at 23:15
  • Make a zero-width vertical selection (drag and drop while pressing ALT) on the right side of text, then you can select Numbering (Alt+N). – Yutaka Dec 15 '22 at 00:01
  • Alternatively, you can select `Marcin:Marcin`, press Ctrl+Shift+A, press End, and select Numbering (Alt+N). – Yutaka Dec 15 '22 at 00:03
  • I was misunderstanding your question. Here is a macro you want to run for EmEditor. I've updated my answer. – Yutaka Dec 16 '22 at 16:33
  • I misunderstood your question. I've updated my answer again. – Yutaka Dec 19 '22 at 18:41
0

I think it would be easier to use EmEditor's \J mode.

Find:^.+$

Replace: \J var str=""; for( i=1; i<100; i++) {str+="\0"+i+"\n"; str.replace(/\n$/g,"");}

var str="" -> Define an empty string

for( i=1; i<100; i++) ->The number of cycles can be changed from 100 to other numbers

str+="\0"+i+"\n" ->Add numbers i and line breaks at the end of the found line \0, and add values to str via str+, connecting them all together

str.replace(/\n$/g,"") ->Clear an extra line break

Screenshot from another link

David.Cao
  • 11
  • 2