如何用Notepad++将奇数行内容追加到对应偶数行末尾?
在Notepad++中合并相邻行(奇数行追加到偶数行末尾)
操作步骤:
- 打开目标配置文件,按下
Ctrl+H调出替换窗口 - 在窗口上方切换到正则表达式模式,同时勾选「匹配换行符」选项
- 在「查找目标」框中输入:
^(static.*)\r\n^(set.*)$ - 在「替换为」框中输入:
\2 \1 - 点击「全部替换」即可完成批量合并
正则说明:
^(static.*):捕获以static开头的整行内容(标记为第1捕获组)\r\n:匹配Windows系统的换行符(如果是Linux/macOS格式的文件,替换为\n即可)^(set.*)$:捕获以set开头的整行内容(标记为第2捕获组)\2 \1:将第2捕获组的内容放在前面,加空格后拼接第1捕获组的内容,实现行内容的调换合并
示例验证:
输入内容:
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"
替换后输出:
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"
内容的提问来源于stack exchange,提问作者PaloAltoSaurus
相关产品推荐
相关产品推荐

