1

我有一个日志文件,一旦找到,我就会尝试存储所有行This has happened due to.,然后开始新行。

所以基本上日志看起来像这样

Bla bla bla bla....This has happened due to.

ABC

DEF

GHI

JKL

一旦我找到“这已经发生由于”这一行,你能帮我匹配一下模式吗?

4

2 回答 2

4
while (<>) {
  next unless /This has happened due to/;
  while (<>) {
    # Process lines
  }
  last;
}
于 2013-05-02T10:03:26.043 回答
3
#!/usr/bin/env perl

while (<>) {
    last if /This has happened due to/;
}

while (<>) {
    print; # do smth with the line
}

将脚本保存到文件并使其可执行。然后像这样运行./script.pl logfile

于 2013-05-02T10:13:59.870 回答