【发布时间】:2012-11-29 12:32:05
【问题描述】:
我有一个看起来像这样的日志文件:
Client connected with ID 8127641241
< multiple lines of unimportant log here>
Client not responding
Total duration: 154.23583
Sent: 14
Received: 9732
Client lost
Client connected with ID 2521598735
< multiple lines of unimportant log here>
Client not responding
Total duration: 12.33792
Sent: 2874
Received: 1244
Client lost
日志包含许多以Client connected with ID 1234 开头并以Client lost 结尾的块。他们永远不会混淆(一次只有一个客户)。
我将如何解析这个文件并生成如下统计数据:
我主要问的是解析过程,不是格式。
我想我可以遍历所有行,在找到 Client connected 行时设置一个标志并将 ID 保存在变量中。然后 grep 行,保存值,直到找到 Client lost 行。这是一个好方法吗?有没有更好的?
【问题讨论】:
标签: bash shell logging sed grep