• Login
Community
  • Login

Join two lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 4 Posters 944 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.
  • B
    bigredcherokee
    last edited by May 4, 2021, 5:58 PM

    So Ctrl-j works when I highlight two lines. Can’t really do a Ctrl-a / Ctrl-j cause that just makes everything one line.

    the first line ending in 0
    the second line looks like this: N 0

    I need to move the second line up to the end of the first line. Like this 0 N 0

    how can I do a find and replace in this document that 2,193 lines?

    P 1 Reply Last reply May 4, 2021, 6:04 PM Reply Quote 0
    • P
      PeterJones @bigredcherokee
      last edited by May 4, 2021, 6:04 PM

      @bigredcherokee

      Use regular expressions:

      • FIND = (?-s)^(.*)\R(.*(\R|\Z))
      • REPLACE = $1 $2
      • REPLACE ALL

      715b8d1c-b810-4f8f-92b1-01924447c2f3-image.png
      =>
      5917c599-be43-4828-899a-ac280033655f-image.png

      (because of the (\R|\Z), it will work whether the last line ends with a newline or EOF)

      ----

      Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

      1 Reply Last reply Reply Quote 0
      • B
        bigredcherokee
        last edited by May 4, 2021, 6:06 PM

        Thanks for that. Forgot to note that not all lines are problems.

        M P 2 Replies Last reply May 4, 2021, 6:13 PM Reply Quote 0
        • M
          Michael Vincent @bigredcherokee
          last edited by Michael Vincent May 4, 2021, 6:16 PM May 4, 2021, 6:13 PM

          @bigredcherokee said in Join two lines:

          Forgot to note that not all lines are problems.

          LOL!!

          https://community.notepad-plus-plus.org/topic/21107/regex-remove-headings-that-has-no-full-stop-at-the-end/10

          1 Reply Last reply Reply Quote 2
          • P
            PeterJones @bigredcherokee
            last edited by May 4, 2021, 7:01 PM

            @bigredcherokee said in Join two lines:

            Thanks for that. Forgot to note that not all lines are problems.

            Okay, that was partly my fault. You said the first ends with 0 and the adjacent line looked like N 0, but I assumed you weren’t telling us the whole story, and since you had originally brought up manual Ctrl+J, I had assumed that it really was “every other line”

            You just have to add 0 to the end of the first group, to force that group to end with a 0; and replace the .* in the second group with the literal N 0 to force that group to contain exact text, not the .* wildcard.

            • FIND = (?-s)^(.*0)\R(N 0(\R|\Z))

            everything else stays the same

            So

            line 1 0
            N 0
            other
            line 4 0
            N 0
            line 6 0
            but doesn't join
            line X 0
            N 0
            

            becomes

            line 1 0 N 0
            other
            line 4 0 N 0
            line 6 0
            but doesn't join
            line X 0 N 0
            

            c2d23584-cc84-49b4-897a-3ff58b0f1791-image.png

            Of course, if you had given example data which showed both lines that should be changed and lines that shouldn’t, we wouldn’t have had this problem.

            @Michael-Vincent linked to @Alan-Kilborn 's

            Maybe we need a template

            As has been proven hundreds of times in the official issues location, people won’t use the template even if it’s literally there every time they start a new issue – and this forum doesn’t have such a feature.

            A B 2 Replies Last reply May 4, 2021, 7:25 PM Reply Quote 1
            • A
              Alan Kilborn @PeterJones
              last edited by May 4, 2021, 7:25 PM

              @PeterJones

              The idea of a “template” was that if people can’t follow it and create an understandable “problem statement”, no one wastes time even responding to them here.

              And yes, there is no way to force a template here AFAIK, but rather they would be directed to a FAQ with the templated questions.

              1 Reply Last reply Reply Quote 1
              • B
                bigredcherokee @PeterJones
                last edited by May 5, 2021, 12:47 PM

                @PeterJones Thanks Peter for the help.

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