Search code examples
stringreplacecommandnotepad++line

Notepad++ Append Line1 Text to the end of Line2, Line3 to Line4, Line5 to Line 6, and so on


I have been Googling my way through manipulating a configuration file to migrate data to another operating system using Notepad++. I have been successful thus far with the plethora of examples and help online with Notepad++. However, I've hit a road block that I'm not able to overcome and require assistance. Here's my plight...

I have a config file of objects, but they are presented in the wrong order for building the command set I need to make this useable. All of the data is presented in an incorrect order. Line 1 should be appended to the end of Line 2, Line 3 should be appended to the end of Line 4, Line 5 should be appended to the end of Line 6, and so on...

static "PMDC1-2019"
set device-group plymouth_meeting address-group "DNS Servers"
static "PMDC2-2019"
set device-group plymouth_meeting address-group "DNS Servers"
static "ExtonDC-2019"
set device-group plymouth_meeting address-group "DNS Servers"
static "wellcall-lodidc"
set device-group plymouth_meeting address-group "DNS Servers"

The end result should be as follows:

set device-group plymouth_meeting address-group "DNS Servers" static "PMDC1-2019"
set device-group plymouth_meeting address-group "DNS Servers" static "PMDC2-2019"
set device-group plymouth_meeting address-group "DNS Servers" static "ExtonDC-2019"
set device-group plymouth_meeting address-group "DNS Servers" static "wellcall-lodidc"

All suggestions and assistance are welcome and appreciated! Thank you.

I've tried to piece together found extended and regex examples without luck. I tried the option and parenthesis method to capture the data and insert it, but failed with that as well. I guess my inexperience with these variables and programming logic are getting the best of me.


Solution

    • Ctrl+H
    • Find what: ^(.+)\R(.+)$
    • Replace with: $2 $1
    • TICK Wrap around
    • SELECT Regular expression
    • UNTICK . matches newline
    • Replace all

    Explanation:

    ^           # beginning of line
    (.+)        # group 1, 1 or more any character
    \R          # any kind of linebreak
    (.+)        # group 2, 1 or more any character
    $           # end of line
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here