0

假设我有 500,000 行以逗号 (,) 结尾,如下所示:

test,'number',null,
test,'number',null,
test,'number',null,

我想在例如每 50,000 行的末尾用 (;) 查找/替换逗号 (,):

line 1:      test,'number',null,
line 50:     test,'number',null,
line 50,000: test,'number',null;

这可能与nodepad ++或emeditor有关吗?

提前致谢

4

2 回答 2

2
  • Ctrl+H
  • 找什么:^(?:[^\r\n]*,\R){49999}[^\r\n]+\K,$
  • 用。。。来代替:;
  • 检查 环绕
  • CHECK 正则表达式
  • Replace all

解释:

^                   # beginning of line
  (?:               # non capture group
    [^\r\n]*        # 0 or more any character but newline
    ,               # a comma
    \R              # any kind of linebreak
  ){49999}          # end group, must appear 49999 times
  [^\r\n]+          # 1 or more non linebreak
  \K                # reset
  ,                 # a comma
$                   # end of line

我有3线条而不是50000例如。

截图(之前):

在此处输入图像描述

截图(之后):

在此处输入图像描述

于 2020-07-04T10:31:16.823 回答
0

EmEditor中,您可以在 500,000 行文档处于活动状态时运行此宏。为此,请将此代码另存为,例如,ReplaceEvery50000.jsee然后从菜单中的选择...中选择此文件。最后,打开您的 500,000 行文档,并在您的 500,000 行文档处于活动状态时选择菜单中的运行。

editor.ExecuteCommandByID(4472);  // ensure non-CSV mode
yLines = document.GetLines();
for( y = 50000; y <= yLines; y += 50000 ) {
    s = document.GetLine( y );
    x = s.length;
    if( s.substr( x - 1, 1 ) == "," ) {
        document.selection.SetActivePoint( eePosLogical, x, y );
        document.selection.SetActivePoint( eePosLogical, x + 1, y, true );
        document.selection.Text = ";";
    }
}
于 2020-07-04T16:09:22.463 回答