• Login
Community
  • Login

How would i combine Every 3 Lines together?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
helphelp
3 Posts 2 Posters 7.7k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Aaron MC
    last edited by Jun 9, 2017, 10:10 PM

    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.

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Jun 10, 2017, 1:24 PM Jun 9, 2017, 10:45 PM

      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

      1 Reply Last reply Reply Quote 0
      • A
        Aaron MC
        last edited by Jun 10, 2017, 4:09 AM

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

        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          3/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors