Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to Join Lines for unformatted lines separated by a blank line intermittantly

    Help wanted · · · – – – · · ·
    3
    7
    993
    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.
    • FDWojo
      FDWojo last edited by FDWojo

      Hey there. I’m a bit confused about the JOIN LINE feature in Notepad++. When you use it, the entire highlighted selection is translated into one single line. Unfortunately, that’s not quite what I’m looking for.

      For what it’s worth, I’ve searched the forum here for “join lines” and none dealt with the case I’m talking about here. The ones that WERE there, dealt with formatted lines and my example does NOT have any recognizable patterns.

      Specifically, I generally edit books, and sometimes I have to reformat them so that the text properly flows. What I’m trying to resolve is so that I could (in theory) highlight a whole group of lines, and join them. BUT… any blank lines in the selected text would NOT be eliminated. Thus, if my text was the following eight lines:

      The rain in Spain falls
      mainly on the plain.

      The quick
      brown fox
      jumps over
      the lazy
      dogs back.

      Please notice the blank line before “The quick brown fox”. After joining, those two “paragraphs” it would result in the following three lines.

      The rain in Spain falls mainly on the plain.

      The quick brown fox jumps over the lazy dogs back.

      As you can see, each “paragraph” will be an uncertain number of lines (typically 1 to 25, and each will be of varying lengths (usually 10 to 70).

      Although I am normally a 64-bit user of NotePad++, I’ve tried the 32-bit version which allows me to use the TEXTFX plugin. But neither it, nor the built-in JOIN LINES feature work the way I need.

      Although I’d like to avoid having to deal with Regex, I’ll do it if that’s my only option. I’ll admit that I’ve been spoiled, because my text editor of choice (before Notepad++) was NoteTab Pro, and its JOIN LINES function works in a way I’m looking for.

      Does anyone have any suggestions?

      And in case anyone suggests it: Yes, I know that I could manually highlight each “paragraph” individually, JOIN it, then do the next, but I have thousands of these “paragraphs” and that would be extremely tedious.

      Thanks for any help in advance if anybody can help.

      Frank

      1 Reply Last reply Reply Quote 0
      • guy038
        guy038 last edited by guy038

        Hello, @fdwojo,

        Welcome to the Notepad++ Community !

        At first sight, I don’t see a native N++ command to achieve this goal :-(

        Luckily, a very simple regex S/R can do the trick :

        • If necessary, do a normal selection of the area where to perform the S/R

        • Open the Replace dialog

        • SEARCH (?-s)(.)\R(?=.)

        • REPLACE \1\x20

        • Tick the In selection option, if you, previously, made a selection

        • Or tick the Wrap around option to act on the whole current file

        • Click once, on the Replace All button or several times on the Replace button


        Notes :

        • First, the in-line modifier (?-s) assures that the dot meta-character ( . ) will stand for a single standard character only ( not EOL chars )

        • Then, the search regex looks for a standard character ((.) ), stored as group1, due to the parentheses, followed with any kind of EOL ( \R )

        • This match is effective ONLY IF the look-ahead assertion is true, i.e. the EOL char(s) is/are followed with a standard character (?=.)

        • In replacement, we rewrites the last character of the line ( \1 ), and replace the EOL char(s) with a single space character ( \x20 )

        An other formulation would be :

        SEARCH (?-s).\K\R(?=.)

        REPLACE \x20

        This time, you must use the Replace All button, exclusively !

        • The \K syntax reset the search location, so the final search is only the EOL character(s)

        Best Regards,

        guy038

        P.S. :

        You can easily record this regex S/R as a macro and assigned it a specific shortcut

        1 Reply Last reply Reply Quote 3
        • FDWojo
          FDWojo last edited by

          Thank you for the quick reply.

          For the first chapter of the book I’m working on, it seems to work pretty well. By the way, not that it changes anything with the problem I was having, but I’m actually working on a book that is written in HTML code, and each “paragraph”, at least tentatively, seems to start with <p> on the first line, and it ends with </p> on the last line, and then a blank line before the next <p>.

          So, I’ll work my way through the remaining 45 chapters and see how things go. As much as I would have preferred to avoid Regex (because it’s difficult since I haven’t figured out how to use it for the REPLACE field syntax), I do really appreciate your providing me with the specific settings in the FIND/REPLACE window.

          If I have any difficulties, I’ll see what I can determine from what you’ve provided and try to put variations in if there are any weird situations.

          I must admit that, as a side note, I wish there was some place to “learn” about Regex, and not just be given the commands without explaining how they work. And lest you think that I am complaining about you, I am not. I am referring to the fact that when I Google about learning Regex, a lot of what I find are just lists of the syntax, and no real in-depth explanation of what each part does.

          But, once again, thank you so much for the help. I hope I can pay it forward to someone later who needs assistance.

          Frank

          1 Reply Last reply Reply Quote 0
          • guy038
            guy038 last edited by guy038

            Hi, @fdwojo,

            Do you mean that your HTML text is like, below :

            <p>
            The rain in Spain falls
            mainly on the plain.
            </p>
            
            <p>
            The quick
            brown fox
            jumps over
            the lazy
            dogs back.
            </p>
            

            And that you expect :

            <p>
            The rain in Spain falls mainly on the plain.
            </p>
            
            <p>
            The quick brown fox jumps over the lazy dogs back.
            </p>
            

            Or, may be, your text looks like :

            <p>The rain in Spain falls
            mainly on the plain.</p>
            
            <p>The quick
            brown fox
            jumps over
            the lazy
            dogs back.</p>
            

            and you would expect :

            <p>The rain in Spain falls mainly on the plain.</p>
            
            <p>The quick brown fox jumps over the lazy dogs back.</p>
            

            Regarding learning regexes, here is a link to enter the regex’s wonderful world ;-))

            https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation/1

            See you later,

            Cheers,

            guy038

            1 Reply Last reply Reply Quote 3
            • FDWojo
              FDWojo last edited by FDWojo

              Sorry if I confused the issue.

              No, to use the example I originally provided, (in HTML) it would have looked like this:

              <p>The rain in Spain falls
              mainly on the plain.</p>

              <p>The quick
              brown fox
              jumps over
              the lazy
              dogs back.</p>

              Thus, it is the second pair of options that I was looking for and, yes, your solution worked perfectly.

              Currently I’ve gotten through about a dozen more chapters, and haven’t run into any problems at all.

              I hope that helped!

              Frank

              P.S. Thanks for the link! I’ll see how dumb I am, or if I’m capable of learning new things!
              ;)

              dinkumoil 1 Reply Last reply Reply Quote 2
              • dinkumoil
                dinkumoil @FDWojo last edited by

                @FDWojo said:

                I’ve tried the 32-bit version which allows me to use the TEXTFX plugin. But neither it, nor the built-in JOIN LINES feature work the way I need.

                I tried it with the TextFX plugin too and it seems it worked like you want:

                Before:

                The rain in Spain falls
                mainly on the plain.
                
                The quick
                brown fox
                jumps over
                the lazy
                dogs back.
                

                After:

                The rain in Spain falls mainly on the plain. 
                
                The quick brown fox jumps over the lazy dogs back. 
                

                I’ve used (menu) TextFX -> TextFX edit -> Unwrap text.

                1 Reply Last reply Reply Quote 3
                • FDWojo
                  FDWojo last edited by

                  I must admit to being a bit embarrassed. I had been looking thru TextFX for a menu item called “JOIN TEXT” and hadn’t found anything. But in looking, I scanned right over the phrase “UNWRAP TEXT”. <oops!>

                  That works perfectly.

                  Thanks for helping to correct an ignorant user.

                  I gotta say that I had noticed other topics in here and a lot of times there were multiple day delays before the original poster got a response. You guys have been so helpful, and responding in only hours, or sometimes minutes.

                  THANK YOU TO BOTH OF YOU!

                  Frank

                  1 Reply Last reply Reply Quote 4
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors