[请教]Perl文件处理
有文本文件如下 a.txt(部分内容)
2006-10-20 03:00:00 : ##START## Executing Institution potential calculation at
...
Msg 515, Level 16, State 2, Server APDB, Procedure sp_ins_potential_calc, Line 187
Cannot insert the value NULL into column 'team_code', table
'taiwan.dbo.BMS_TEMP'; column does not allow nulls. INSERT fails.
The statement has been terminated.
2006-10-20 03:00:04 : ##END## Executing Institution potential calculation at .
..
It took 3656 ms.
2006-10-20 03:00:04 : ##START## Executing Spec and Audience Update Process ...
要用perl语言来分析这个文件。要求看到Msg的话,那么将输出从Msg前的最近一个时间开始,直到下一个时间为止,如上面的这种情况,就要输出下面内容到新的文件里。
2006-10-20 03:00:00 : ##START## Executing Institution potential calculation at
...
Msg 515, Level 16, State 2, Server APDB, Procedure sp_ins_potential_calc, Line 187
Cannot insert the value NULL into column 'team_code', table
'taiwan.dbo.BMS_TEMP'; column does not allow nulls. INSERT fails.
The statement has been terminated.
小弟,初使用perl,目前只能做到将有Msg的那一行输出。代码大致如下:
#orignalLogFile为需要解析的文件,INPUT为要输出的目标文件
while(<orignalLogFile>) {
if( /^Msg/ ) {
print INPUT ($_);
}
}
有没有办法,在匹配到Msg后,再回到之前的日期那一行,然后开始输出,直到下一个日期之前?还请各位大虾指教