How to merge lines every 3 rows in Notepad++?
Like this:
A
B
C
D
E
F
G
H
I
To this:
A B C
D E F
G H I
It's a 2500 rows file, so i wouldn't just ctrl+j it.
Solution 1:
Hit Ctrl+H to access the Replace dialog, tick Regular expression, and enter the above expressions. Here it is in text:
Find what: (.+)\r\n(.+)\r\n(.+)
Replace with: \1\t\2\t\3\t
(the last \t
is optional; you won't visually notice any difference if you remove it, unless you are expecting the line to end with a tab character)
Replace \r\n
in the "Find what:" with:
-
\n
if you are editing a file with UNIX-style line endings (linefeed only) -
\r\n
if you are editing a file with Windows-style line endings (carriage return followed by line feed; in this case, you don't need to modify the original regex) -
\r
if you are editing a file with traditional Mac-style line endings (carriage return only)
You can find out which line ending you're using by examining the status bar at the bottom of the Notepad++ window. It will say "Dos\Windows", etc.
If your file has inconsistent line endings (which is a bad thing in general, but not impossible) and you want to replace all possible types of newlines in one go:
Find what: (.+)(\r|\n)+(.+)(\r|\n)+(.+)
Replace with: \1\t\3\t\5\t
You can learn more about regular expressions here.