轻松解析mbuffer的时间和速度输出?

时间:2013-04-16 15:24:31

标签: regex perl parsing

我有mbuffer将其输出放入文件中。每个文件一行,其中3个例子可以是

summary:  0.0 KiByte in  0.3 sec - average of  0.0 B/s
summary:  0.0 KiByte in  12 h 24 min - average of  12.0 KiB/s
summary:  0.0 KiByte in  12 min - average of  12.0 MiB/s

我想以秒为单位提取时间,以MB / s为单位提取速度。

问题

有一种简单的方法吗?因为我只能想到能够提供长期正则表达式的东西。

1 个答案:

答案 0 :(得分:2)

/summary:.*?in\s*(?:(?<hours>[\d\.]+) h)?\s*(?:(?<minutes>[\d\.]+) min)?\s*(?:(?<seconds>[\d\.]+) sec)?.*?average of\s*(?<speed>[\d\.]+ [a-zA-Z]+\/s)/g

..将创建4个命名捕获组:

  • seconds(包含秒,例如。0.3
  • minutes(包含分钟,例如。24
  • hours(包含小时数,例如12
  • speed(附加B / KiB / MiB的平均速度,例如12.0 KiB/s

DEMO

<强>输出

enter image description here

相关问题