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 3aThis 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$0with 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login