perl程序以任意顺序解析三个令牌

时间:2014-08-05 10:13:42

标签: perl parsing

我需要解析一个buillog,其中有三个令牌(或关键字)以任意顺序排列。请帮忙。

HBStartArchiverList  - Command indicates the start of addition of list of objects at command HBAddObjectToArchiverList , HBFinishArchiverList indicates the completion of addition. HBAddObjectToArchiverList may appear one or more between start and finish.




     -- pattern1 -- easy to parse ------------
   HBStartArchiverList E:\AA\BB\CC\a.txt
   HBAddObjectToArchiverList E:\AA\BB\CC\a.txt
   HBFinishArchiverList E:\AA\BB\CC\a.txt
   ------------------------------------------

   -- pattern2 -- easy to parse ------------
   HBStartArchiverList E:\AA\BB\CC\b.txt
   HBAddObjectToArchiverList  E:\AA\BB\CC\b.txt
   HBAddObjectToArchiverList  E:\AA\BB\CC\b.txt
   HBAddObjectToArchiverList  E:\AA\BB\CC\b.txt
   HBAddObjectToArchiverList  E:\AA\BB\CC\b.txt
   HBFinishArchiverList  E:\AA\BB\CC\b.txt
   --------------------------------------------

 ----pattern3 -----Difficult to parse---
     HBStartArchiverList E:\AA\BB\CC\c.txt
     HBAddObjectToArchiverList E:\AA\BB\CC\c.txt
     HBStartArchiverList E:\AA\BB\CC\d.txt
     HBFinishArchiverList E:\AA\BB\CC\c.txt
     HBAddObjectToArchiverList E:\AA\BB\CC\d.txt
     HBFinishArchiverList E:\AA\BB\CC\d.txt
  ---------------------------------------
pattern3 is difficult because i expect c.txt to finish, but d.txt start appears before finish of c.txt.



 -----pattern4 -----Difficult to parse----
 HBStartArchiverList E:\AA\BB\CC\e.txt
 HBStartArchiverList E:\AA\BB\CC\f.txt
 HBAddObjectToArchiverList E:\AA\BB\CC\e.txt
 HBAddObjectToArchiverList E:\AA\BB\CC\f.txt
 HBFinishArchiverList E:\AA\BB\CC\e.txt
 HBFinishArchiverList E:\AA\BB\CC\f.txt
 -----------------------------------------**

pattern4是e.txt的难点,f.txt是一个接一个地出现。

**指----

Line 16064: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser_common.a_Objects.txt

  Line 16069: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser_common.a_Objects.txt

  Line 16079: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser_common.a_Objects.txt

  Line 16098: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libimp_ntg5_onlineservices_browser_common.a 
  Line 17954: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17959: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17964: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17969: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17974: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17986: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 17991: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 18003: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libimp_ntg5_onlineservices_browser.a_Objects.txt 
  Line 18012: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libimp_ntg5_onlineservices_browser.a

  Line 18024: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdmsconfig.a_Objects.txt

  Line 18029: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdmsconfig.a_Objects.txt

  Line 18034: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdmsconfig.a_Objects.txt

  Line 18043: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libdmsconfig.a

  Line 18108: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginsCommonS.a_Objects.txt

  Line 18113: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libntg5_browser_audiosource_dsi.a_Objects.txt

  Line 18118: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginsCommonS.a_Objects.txt

  Line 18123: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libntg5_browser_audiosource_dsi.a_Objects.txt

  Line 18128: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libntg5_browser_audiosource_dsi.a_Objects.txt

  Line 18133: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginsCommonS.a_Objects.txt

  Line 18142: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginsCommonS.a

  Line 18150: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libntg5_browser_audiosource_dsi.a

  Line 18270: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseS.a_Objects.txt

  Line 18275: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libnpapitraceS.a_Objects.txt

  Line 18280: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseS.a_Objects.txt

  Line 18285: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libnpapitraceS.a_Objects.txt

  Line 18290: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseS.a_Objects.txt

  Line 18295: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libnpapitraceS.a_Objects.txt

  Line 18300: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginBaseS.a

  Line 18312: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libnpapitraceS.a

  Line 18328: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseMocca.a_Objects.txt

  Line 18340: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseMocca.a_Objects.txt

  Line 18345: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBaseMocca.a_Objects.txt

  Line 18354: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginBaseMocca.a

  Line 18452: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBase.a_Objects.txt

  Line 18462: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBase.a_Objects.txt

  Line 18474: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginBase.a_Objects.txt

  Line 18484: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginBase.a

  Line 18538: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUI.a_Objects.txt 
  Line 18543: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUI.a_Objects.txt 
  Line 18555: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUI.a_Objects.txt 
  Line 18571: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginUI.a

  Line 18625: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt

  Line 18630: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt

  Line 18635: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt

  Line 18651: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libPluginUICairo.a

  Line 20103: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20108: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20113: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20118: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20123: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20128: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclients.a_Objects.txt

  Line 20144: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libdsiclients.a

  Line 21436: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21448: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21453: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21465: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21470: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21475: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libdsiclientsS.a_Objects.txt

  Line 21487: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\imp\libdsiclientsS.a

  Line 21580: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest_dsi.a_Objects.txt

  Line 21585: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest_dsi.a_Objects.txt

  Line 21594: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest.a_Objects.txt 
  Line 21599: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest_dsi.a_Objects.txt

  Line 21604: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest.a_Objects.txt 
  Line 21613: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_nav_ctrl_NTG5_extdest.a_Objects.txt 
  Line 21618: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libapi_nav_ctrl_NTG5_extdest_dsi.a

  Line 21639: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\deliveries\libapi_nav_ctrl_NTG5_extdest.a

  Line 21772: HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_ntg5_onlineservices_favoritesmanager.a_Objects.txt 
  Line 21777: HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_ntg5_onlineservices_favoritesmanager.a_Objects.txt 
  Line 21782: HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libapi_ntg5_onlineservices_favoritesmanager.a_Objects.txt 
  Line 21791: Archive E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\lib\api\libapi_ntg5_onlineservices_favoritesmanager.a
     

--------- **

以下是样本日志

**-----------------------
HBStartArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt 
    PATH=C:\Perl\bin
    perl E:\P4\Onlineservices\buildprocess\tools\perl\util\slashify.pl "CREATE libPluginUICairo.a" >> E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt

HBAddObjectToArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt 
    PATH=C:\Perl\bin
    perl E:\P4\Onlineservices\buildprocess\tools\perl\util\slashify.pl "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\ICairoWidget.o" "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\CCairoContext.o" "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\CColor.o" "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\CProgressBarCairoWidget.o" "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\CScrollCairoWidget.o" "ADDMOD E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\bin\deliveries\ntg5\intel\api\scp\HBWebkitPluginSDK\PluginBase\PluginUI\Cairo\private\CScrollTheme.o" >> E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt

HBFinishArchiverList E:\P4\Onlineservices_products\x86-qnx-m650-4.4.2-osz-trc-rel\tmp\libPluginUICairo.a_Objects.txt 
--------------------------**

当我遇到上面的“开始”时,我希望“添加”令牌,然后解析后续列表o f.o文件,然后当我遇到“完成”时,我将停止收集该档案的.o文件。在模式(3和4)中解释。两个或更多“start”出现在日志文件中的“add”之前,这些情况很难解析。请帮忙。

1 个答案:

答案 0 :(得分:0)

如上所述,这不是一个解析问题。对于您提供的每个样本,解析文件同样容易。

while (<>) {
   chomp;
   my ($action, $path) = split(' ', $_, 2);
   ...
}

所以我们要猜测你想要做什么。是按路径对行动进行分组吗?

my %actions_by_path;
while (<>) {
   chomp;
   my ($action, $path) = split(' ', $_, 2);
   push @{ $actions_by_path{$path} }, $action;
}