提取时间戳并找出差异

提取时间戳并找出差异

我有一大组日志,如下所示:

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 .

相关内容