【问题标题】:Move second line to end of third line // notepad++将第二行移到第三行末尾 // notepad++
【发布时间】:2018-08-22 20:54:03
【问题描述】:

我有以下 txt 文件,其中包含一个三行并重复的块(总共 4000 行):

Printer1
/900
HBA/8/7
Printer2
/800
HBA/7/2

现在我想将第二行移到第三行的末尾,然后重复(第 5 行到第 6 行的末尾;第 8 行到第 9 行的末尾,依此类推)

这可以用notepad++完成吗?或者也许是 Excel 宏?我找到了一些使用正则表达式和 vmi 的示例,但问题是他们正在寻找关键字。我只想将整个第 2 行移到第 3 行的末尾...然后继续模式 (5th->6th; 8th->9th)

非常感谢任何意见/想法/解决方案。

亲切的问候

米奇

【问题讨论】:

    标签: excel notepad++ vba


    【解决方案1】:

    好吧,有时一点时间会带来想法:)

    我刚刚在 Excel 中导入了 txt 文件,所以第 1 行是“Printer1”,第 2 行是“/900”,依此类推。 然后我就这样做了:

    B1 =A1
    B2 =A3&A2
    B3 =empty
    

    然后我只是将 B1 标记为 B3 并按下 ctrl 键将其拖动到文件末尾。等等,我有我需要的东西。现在我只是将 B 列复制到新的 txt 文件中,一切都很好:)

    【讨论】:

      【解决方案2】:
      • Ctrl+H
      • 查找内容:^.+\R\K(.+\R)(.+\R)
      • 替换为:$2$1
      • 检查环绕
      • 检查正则表达式
      • 请勿查看. matches newline
      • 全部替换

      说明:

      ^           : beginning of line
        .+        : 1 or more any character but newline (ie. the first line)
        \K        : forget all we have seen until this position
        (.+\R)    : Group 1, 1 or more any character followed by linebreak (ie. the second line)
        (.+\R)    : Group 2, 1 or more any character followed by linebreak (ie. the third line)
      

      替换:

      $2      : content of group 2
      $1      : content of group 1
      

      给定示例的结果:

      Printer1
      HBA/8/7
      /900
      Printer2
      HBA/7/2
      /800
      

      【讨论】:

        猜你喜欢
        • 2015-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-27
        • 2015-04-21
        • 2015-06-02
        相关资源
        最近更新 更多