在perl中的特定行之后搜索行

时间:2013-05-02 09:56:46

标签: perl

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

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

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

ABC

DEF

GHI

JKL
一旦我找到“这是因为发生了这条线”,你能不能请我帮助我匹配这个地板。

2 个答案:

答案 0 :(得分:4)

while (<>) {
  next unless /This has happened due to/;
  while (<>) {
    # Process lines
  }
  last;
}

答案 1 :(得分:3)

#!/usr/bin/env perl

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

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

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

一样运行
相关问题