Join two lines



  • 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?



  • @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.



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





  • @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.



  • @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.



  • @PeterJones Thanks Peter for the help.


Log in to reply