提取時間戳並找出差異

提取時間戳並找出差異

我有一大組日誌,如下圖:

June   5 15:51:56.606  [3997]:   TR#153. State machine - state = CC_STATE_IDLE, event = EVT_ISDN_SETUP
June   5 15:51:56.607  [3997]:   TR#153):  SC registration SUCCESS.
June   5 15:52:00.368  [3997]:   TR#153. DSP:4 Channel:26 Type: Modem State: Data 
June   5 15:52:01.837  [3997]:   TR#153. Receive transaction data: prot 1 data length: 159.-------------------->>
June   5 15:52:02.073  [3997]:   TR#153. Send transaction data: 55 <<-------------------
June   5 15:52:04.361  [3997]:   TR#153):Disconnect initated by 32 process.
June   5 15:52:57.382  [3997]:   TR#153. State machine - state = CC_STATE_IDLE, event = EVT_ISDN_SETUP
June   5 15:52:57.383  [3997]:   TR#153):  SC registration SUCCESS.
June   5 15:53:01.327  [3997]:   TR#153. DSP:4 Channel:26 Type: Modem State: Data 
June   5 15:53:04.291  [3997]:   TR#153. Receive transaction data: prot 1 data length: 347.-------------------->>
June   5 15:53:05.071  [3997]:   TR#153. Send transaction data: 103 <<-------------------
June   5 15:53:06.209  [3997]:   TR#153. Receive transaction data: prot 1 data length: 24.-------------------->>
June   5 15:53:07.239  [3997]:   TR#153):Disconnect initated by 32 process.

我想找到事件“EVT_ISDN_SETUP”和“Disconnect”之間的時間差,本質上是每個事務的持續時間。為此,我需要先從相應的行中提取時間戳並找出差異。我嘗試了 Perl 程式碼這裡找出一個實例的差異,效果很好。我的任務是成功取得感興趣事件的時間戳,然後輸入 Perl 程式碼並列印差異以及 TR#ID。

我該怎麼辦?

答案1

假設:對於包含模式的每一行,EVT_ISDN_SETUP都有包含Disconnect模式的行。讓我把演算法貼給你:

  Get the time field for the line matching `EVT_ISDN_SETUP` pattern and put it to temp1 file
  Get the time field for the line matching `Disconnect`pattern and put it to another file say temp2.
  Using paste command put the content of both the files to another file say temp3.
  Read every line of the temp3 and pass first & 2nd field your perl script .

相關內容