0

我需要从日志中匹配并提取带有 pattern1 的行,该行应该位于另一个 pattern2 匹配行之后:例如,日志具有如下数据:

00:00:01 Computing CDA.
00:01:10 Trying to open errorLog1.
00:01:12 writing errorLog1.
00:01:13 Trying to open outLog1.
00:01:14 writing outLog1.
00:01:15 Processing Complete!
00:01:16 Validating documents.
00:02:14 Trying to open errorLog2.
00:02:12 writing errorLog2.
00:02:13 Trying to open outLog2.
00:02:14 writing outLog2.
00:02:15 Processing Complete!

我需要计算文档验证所需的时间(第一列)。所以我想用“Validating document”字符串和“Processing Complete”字符串检索行来提取时间并得到差异。这可能很容易,但我无法找出解决方案。

4

2 回答 2

1

这应该有效:

if ($subject =~ m/(\d{2}:\d{2}:\d{2}) Validating documents\..*?(\d{2}:\d{2}:\d{2}) Processing Complete!/s) {
    $start = $1;
    $end = $2;
    # Calculating the time difference is left as an exercise :)
}
于 2013-05-10T05:53:29.920 回答
0
perl -lane '$a=$F[0] if(/Validating documents/);if(/Processing Complete/){print $F[0]-$a}' your_file

我只是$F[0]-$a在代码中提到了,但它不是计算时间的方式。但那是你工作并计算时间差的部分。$F[0]保存在该行中遇到处理完成的时间

于 2013-05-10T06:07:53.603 回答