Duplicate Each Block of Lines Consecutively
-
Hello everyone, I’ve been trying to find a way to duplicate each block of lines consecutively. The only thing I found so far is to use CTRL+D, but it will be troublesome to use it on a large text file since I have to do it manually for each block. Is there any way to do it at once using Notepad++?
This is the example:
1 line 1 line 1a 2 line 2 line 2a 3 line 3 line 3a
This is the desired result:
1 line 1 line 1a 1 line 1 line 1a 2 line 2 line 2a 2 line 2 line 2a 3 line 3 line 3a 3 line 3 line 3a
-
@Mayonnaisu said in Duplicate Each Block of Lines Consecutively:
Thanks for using code blocks. it made it easy to copy/paste and test the regex.
The simplest would be to use FIND =
(?s)^.*?\R\R
, replace =$0$0
with regular-expression mode – that allows.
to match newlines, and finds the shortest sequence that has two newlines in a row (the\R\R
).
But unless you had two blank lines after the 3rd group, that wouldn’t work for the third group.Some experimenting showed that the most reliable was FIND =
(?s)^(.*?)(\R)(\R|\Z)
and REPLACE =$1$2$2$1$2$2
– that way, there doesn’t have to be two blank lines (though there does need to be a newline after the third group).----
Useful References
-
@PeterJones Thanks for the solution! I really appreciate that. So it turns out that I can use regex to do it. I’m embarassed that my regex skill hasn’t improved much. It seems to decline instead after long hiatus. If time allows, I want to relearn it so that I don’t have to keep asking here.