[请教]Perl文件处理

topmind2005 2006-10-24 04:21:52
有文本文件如下 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后,再回到之前的日期那一行,然后开始输出,直到下一个日期之前?还请各位大虾指教
...全文
258 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
iambic 2006-10-24
  • 打赏
  • 举报
回复
while(<orignalLogFile>) {
if(/##START##/) {
$timeline = $_;
}
if( /^Msg/ ) {
print INPUT $timeline;
print INPUT ($_);
}
}

37,716

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧