How would i combine Every 3 Lines together?



  • lets say i have a list in order such as :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    etc.

    How would i be able to make Line 1, 2, 3 Join together so they look
    123,
    and also how would i do it with the rest of the text?
    so in the end it should be
    123
    456
    789
    etc.

    What im trying to do is Make Every 3 Lines join. Im not sure how to and if i press Ctrl + J after highlighting the first three it takes forever to do all manually.



  • Hello, @aaron-mc,

    Not difficult with regular expressions !!

    So, from your example, to get the text :

    123
    456
    789
    

    use the reges S/R, below :

    SEARCH (?-s)^(.+)\R(.+)\R(.+)\R

    REPLACE \1\2\3\r\n

    Of course, don’t forget to check the Regular expression search mode !

    Notes :

    • The first part (?-s) means that any dot, in the regex, will stand for an unique standard character, exclusively

    • Then, the symbol ^ is an assertion, looking for a beginning of line

    • Next, the part (.+)\R, searches an entire, NON empty, line, with its End of Line characters, whatever they are and stored as group 1, due to the parentheses

    • Finally, the two next syntaxes (.+)\R look for the next two complete lines, stored as group 2 and group 3

    • In replacement, these three lines are re-written, one after another, on a same line, followed by the Windows End of Line characters. For Unix files, use the regex \1\2\3\n, instead


    For a real text example, as below :

    This
    is
    a
    very
    simple
    text
    to
    test
    if our
    S/R
    works
    properly !
    

    We would obtain the text :

    This is a
    very simple text
    to test if our
    S/R works properly !
    

    Remark :

    • Of course, as the different words must be separated by a space character, the replace regex must be changed into the regex :
      \1 \2 \3\r\n, with a space character after the \1 and \2 back-references !

    Best Regards,

    guy038



  • Thank you man it worked! You came clutch for me. :)