Samplelog.log
Log Level A | Start log creation | 123456789
Logging System start
Checking data cache
Sending out email
Stop log creation |
Log Level A | Start log creation | 987654321
Logging System start
Checking data cache
Sending out email
Stop log creation | 987654321
Log Level A | Start log creation | 121212121
注意: 123456789,987654321和121212121是交易ID
对于上面的日志文件,如何使用head,tail和grep导致以下截断日志: -
Log Level A | Start log creation | 987654321
Logging System start
Checking data cache
Sending out email
Stop log creation | 987654321
所以,基本上我的要求是检查事务ID的第一个实例 - 987654321并将日志拉到此事务ID的最后一个实例。此外,日志文件非常庞大,因此该方法也需要处理它。
答案 0 :(得分:0)
你可以使用这个awk:
awk -v id=987654321 '/ Start log / && $NF==id{p=1}
p; /^Stop log / && $NF==id{exit}' sample.log
Log Level A | Start log creation | 987654321
Logging System start
Checking data cache
Sending out email
Stop log creation | 987654321