Notepad++ - Merge all lines into one and add separator
So this is my situation: I have a lot of lines like this:
line1 line2 line3 line4And 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 | line4How can I do this?
3 Answers
No regex required in this case.
Edit > Blank Operations > Trim leading Space.
Replace All "\r\n" with " | " (make sure Extended Search Mode is selected):
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:
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