Copy every X line

2. Help
  • LostProphet

    I have an xml file, which contains important texts in every 5th line. Is there a way to automatically highlight (or copy) every X line?

  • Loreia2

    HI lostprofeta ,

    you can't do this in editor. You must make a script to do the job.


  • cchris

    Use TextFX Add line numbers feature to add line numbers. Then, use a regular expression to find lines that start with numbers followed by 0 or 5 and a blank:
    Copy marked lines, and use TextFX to remove the line numbers.


  • Fool4UAnyway

    This is something I would typically use the macro feature for.

    The easiest way to get what you want is to remove 4 lines and then skip the fifth.
    If you record that in a macro, put the cursor on top of your original document and playback this macro until the end of the document, you should face it.

    Do not overwrite you original document, save your remainders with another filename.

    Another way is to record a macro that does the following:
    1. Move down 4 lines
    2. Press F2 to bookmark the 5th line

    Playback this from the top until the end of the document.

    You can then also copy the bookmarked lines and paste them into a new document.


    Hi LostProphet,

    In addition to the methods of Cchris and Fool4UAnyway, I think we can do
    the job, very easily, with the Regular Expression mode, in N++, from the
    6.0 version or higher !

    • Copy all your file in a NEW file ( CTRL + A, CTRL + N, CTRL + V )

    • Move back to the BEGINNING of this NEW file ( CTRL + Origin )

    • Open the Search-Replacement window ( CTRL + H )

    • Type (.*\R){5} in the Search dialog

    • Type \1 in the Replacement dialog

    • Choose the " Regular expression " Search mode

    • Click ONCE on the " Replace All " button or the " Replace "
      button, as many as necessary !

    Notes :

    • Your file MUST NOT contain any " Form Feed " character ( \x0c ) because the
      dot symbol doesn't recognize the Form Feed character as a normal character !

    • .*\R stands for a COMPLETE line ( ALL the characters + EOL character(s) )

    • \1 stands for the LAST value of the string .*\R ( = the FIFTH line )

    • Of course, ANY NUMBER > 1 can be used, between BRACES {}, instead of value 5 !

    • AFTER the GLOGBAL replacement, 1 up to 4 lines, at the END of the file, may be
      not changed, because the NUMBER of lines of your file is NOT a FIVE multiple !

    As you can see, most of a time, there's several ways to do the same thing with N++ !!



    P.S. You can also find some documentation, about the new PRCE Regular Expressions, used by N++, since the
    6.0 version, at the two adresses below :

     The FIRST one concerns the syntax of regular expressions in the SEARCH part
     The SECOND one concerns the syntax of regular expressions in the REPLACEMENT part
    Last edit: THEVENOT Guy 2013-01-02