我有文件 log.txt :
======================
Tue Jun 25 00:02:00 WIT 2013
======================
pool
INFO name work
INFO threads.total 30
INFO threads.active 7
INFO threads.waiting 23
INFO jobs.queue.latency 0
INFO jobs.run.latency 139
INFO jobs.queue.tps 3
INFO jobs.start.tps 3
INFO jobs.finish.tps 3
NORMAL jobs.count 0
pool
INFO name recv
INFO threads.total 40
INFO threads.active 27
INFO threads.waiting 13
INFO jobs.queue.latency 0
INFO jobs.run.latency 0
INFO jobs.queue.tps 0
INFO jobs.start.tps 0
INFO jobs.finish.tps 0
NORMAL jobs.count 0
pool
INFO name send
INFO threads.total 10
INFO threads.active 0
INFO threads.waiting 10
INFO jobs.queue.latency 0
INFO jobs.run.latency 1
INFO jobs.queue.tps 5
INFO jobs.start.tps 5
INFO jobs.finish.tps 5
NORMAL jobs.count 0
======================
Tue Jun 25 00:03:00 WIT 2013
======================
pool
INFO name work
INFO threads.total 30
INFO threads.active 15
INFO threads.waiting 15
INFO jobs.queue.latency 0
INFO jobs.run.latency 13
INFO jobs.queue.tps 1
INFO jobs.start.tps 0
INFO jobs.finish.tps 0
NORMAL jobs.count 46
INFO jobs.1.type request
pool
INFO name recv
INFO threads.total 40
INFO threads.active 27
INFO threads.waiting 13
INFO jobs.queue.latency 0
INFO jobs.run.latency 0
INFO jobs.queue.tps 0
INFO jobs.start.tps 0
INFO jobs.finish.tps 0
NORMAL jobs.count 0
pool
INFO name send
INFO threads.total 10
INFO threads.active 0
INFO threads.waiting 10
INFO jobs.queue.latency 0
INFO jobs.run.latency 0
INFO jobs.queue.tps 0
INFO jobs.start.tps 0
INFO jobs.finish.tps 0
NORMAL jobs.count 0
我想要这样的结果:
======================
Tue Jun 25 00:03:00 WIT 2013
======================
INFO name work
NORMAL jobs.count 46
INFO jobs.1.type request
我已经使用:
cat log.txt |grep -B14 -A1 -i 'jobs.count [1-9]\{2,\}' |
egrep -i "jobs.1.type|=|WIT|jobs.count [1-9]"
如果名称不是“work”而是“send”或“recv”,那么“grep -B14”将无法获取日期。还有其他解决方案吗?另一方面,如果“jobs.count”不是“0”,我想要grep而不是get date =“Tue Jun 25 00:03:00 WIT 2013”,get name =“INFO name work”并获得工作类型“INFO jobs .1.类型请求”: