Reputation: 6725
I have a file text with a large data like this :
A
B
C
D
E
F
G
H
I
J
I want group each 5 line into one line like this:
ABCDE
FGHIJ
I try with this Regex, but it not working
Find What: (\r\n{3})
Replace with: $1\n
Any suggestion please ?
Upvotes: 1
Views: 46
Reputation: 1
If you want to do this using notepad++, and if using regex is not an absolute requirement you could also use a simple macro like this:
Now play this macro multiple times until end of file (Macro -> Run A Macro Multiple Times)
Upvotes: 0
Reputation: 626853
You can use
^(.*)\R(.*)(?:\R(.*))?(?:\R(.*))?(?:\R(.*))?
To replace with $1$2$3$4$5
. The \R
stands for any linebreak style, CRLF, CR, or LF. The ^
is necessary (start of line) to make sure we start counting lines from the next after a successful match.
Also note that we need to have at least 1 linebreak to start "merging" lines (see (.*)\R(.*)
in the beginning of the pattern).
Pattern details:
^
- start of line(.*)\R
- a line with a linebreak at the end, the contents of which are captured into Group 1(.*)
- (Group 2) line after the first one captured(?:\R(.*))?
- optional (1 or 0) linebreak followed with some (0 or more) characters other than a newline (Group 3)(?:\R(.*))?
- ibid. (Group 4)(?:\R(.*))?
- ibid. (Group 5) See the screen below:
Upvotes: 0
Reputation: 29431
I would do this like so:
(?:(.*)\r\n)(?:(.*)\r\n)?(?:(.*)\r\n)?(?:(.*)\r\n)?(?:(.*)\r\n)?
And replace with: $1$2$3$4$5\n
Upvotes: 1