我有这个日志,我想打印带有"已完成"的行。"数量限制"的职位状态0";
INFO 2021-01-19 02:00:00,001 JOB: 0970b711] starting
INFO 2021-01-19 02:00:01,001 JOB: 0970b711] adding records
INFO 2021-01-19 02:00:02,001 JOB: 0970b711] registered
INFO 2021-01-19 02:00:03,001 JOB: 0970b711] QTY REGS: 3 processing
INFO 2021-01-19 02:00:03,001 JOB: 32970g233] debug started
INFO 2021-01-19 02:00:04,001 JOB: 0970b711] finished
INFO 2021-01-19 02:00:05,001 JOB: 10d0g655] starting
INFO 2021-01-19 02:00:06,001 JOB: 10d0g655] QTY REGS: 0 processing
INFO 2021-01-19 02:00:07,001 JOB: 10d0g655] finished
INFO 2021-01-19 02:00:08,001 JOB: 0870a711] starting
INFO 2021-01-19 02:00:09,001 JOB: 0870a711] QTY REGS: 1 processing
INFO 2021-01-19 02:00:10,001 JOB: 0870a711] retry
INFO 2021-01-19 02:00:11,001 JOB: 0870a711] connect error
INFO 2021-01-19 02:00:12,001 JOB: 0870a711] finished
我想返回
INFO 2021-01-19 02:00:03,001 JOB: 0970b711] QTY REGS: 3 processing
INFO 2021-01-19 02:00:09,001 JOB: 0870a711] QTY REGS: 1 processing
是QTY REGS>0具有相同作业编号但已"完成"的行。作为描述
INFO 2021-01-19 02:00:04,001 JOB: 0970b711] finished
INFO 2021-01-19 02:00:12,001 JOB: 0870a711] finished
我建议使用数组:
awk '$6=="QTY" && $8>0{a[$5]=1}; $6=="finished" && a[$5]==1{print}' file
输出:
[pre] INFO 2021-01-19 02:00:04 . 001 JOB: 0970b711]完成INFO 2021-01-19 02:00:12,001 JOB: 0870a711] finished{print}
也可以省略。