11

So this is my situation: I have a lot of lines like this:

line1
     line2
              line3
     line4

And they all start with different spaces. What I want to do is merge all the lines in the document into one, but separate each one with some character, something like this:

line1 | line2 | line3 | line4

How can I do this?

4 Answers 4

27

No regex required in this case.

  1. Edit > Blank Operations > Trim leading Space.

  2. Replace All "\r\n" with " | " (make sure Extended Search Mode is selected):

    1

8
  • Awesome works perfect. Can I ask you if can do this operation but only with the bookmarked lines? Of course just the step 2. I see i can select them and then use the "In selection" checbox but I use the bookmark function to bookmark all lines that contains a certain word
    – Hyperion
    May 17, 2015 at 20:24
  • Don't think that's possible directly, but you can use Search > Bookmark > Cut bookmarked lines, paste in a temporary file, do the above and cut-paste back.
    – Karan
    May 17, 2015 at 20:28
  • Uhm seems not working with a macro, at least when copy back step.
    – Hyperion
    May 17, 2015 at 20:43
  • What does not work precisely? And what does "when copy back step" mean?
    – Karan
    May 17, 2015 at 20:46
  • When I do the operation in the document 2 all goes fine, but when I try to cut the new line (witch is in document 2 and cointains all the merged lines), he doesn't record the "past this line in document 1".
    – Hyperion
    May 17, 2015 at 20:57
1

As @Karan answers regex it's not necessary to solve your question, anywise you can use it to do it in one step and to avoid errors with different UNIX/Windows end lines (\n or \r\n).

To do so you can use the Replace All "\s*(.+)\s+" with "$1 | " with Regular Expression mode selected:

enter image description here

1

Actually, a much simpler way is to go to Edit/Line Operations/Join Lines. It's a built-in function that works in one easy click.

2
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 3, 2023 at 11:54
  • This will not remove extra spaces.
    – Toto
    May 3, 2023 at 12:54
0

This is how I do it very easily. Let's say I want to merge all my lines but separate them with a semi colon.

Remove any headers Select from end of first line (hold shift key) to beginning of second line

Then Control H

This will bring up your Replace dialog box where the "Find what:" will be blank, and the "Replace with:" enter your separator like the semi colon ;

Then Replace All

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .