Search code examples
notepad++emeditor

How to find/replace a character in every specific line


assume i have 500,000 line ends with comma (,) like this:

test,'number',null,
test,'number',null,
test,'number',null,

i want to find/replace comma (,) with (;) in the end of for example every 50,000 line:

line 1:      test,'number',null,
line 50:     test,'number',null,
line 50,000: test,'number',null;

is that possible to do with nodepad++ or emeditor?

thanks in advance


Solution

  • In EmEditor, you can run this macro while your 500,000 line document is active. To do this, save this code as, for instance, ReplaceEvery50000.jsee, and then select this file from Select... in the Macros menu. Finally, open your 500,000 line document, and select Run in the Macros menu while your 500,000 line document is active.

    editor.ExecuteCommandByID(4472);  // ensure non-CSV mode
    yLines = document.GetLines();
    for( y = 50000; y <= yLines; y += 50000 ) {
        s = document.GetLine( y );
        x = s.length;
        if( s.substr( x - 1, 1 ) == "," ) {
            document.selection.SetActivePoint( eePosLogical, x, y );
            document.selection.SetActivePoint( eePosLogical, x + 1, y, true );
            document.selection.Text = ";";
        }
    }