我想从下面的文本文件中提取特定单词,即PassThroughHandlerJob: 2299 succeeded, 0 failed, 0 pending
。
在日志文件2299中,成功计数每天都在变化。并且计数可能每天都有所不同,因为失败,未决和成功。
NewFile.txt
2014-07-10 22:28:13,193 INFO [mainScheduler_Worker-28] [com.myvest.sps.scheduler.jobs.AbstractDistributedJob] Checked the status of 2299 work units for job PassThroughHandlerJob: 2299 succeeded, 0 failed, 0 pending
2014-07-10 22:28:21,859 INFO [mainScheduler_Worker-28] [com.myvest.sps.scheduler.jobs.success.PassThroughHandlerJob] Job PassThroughHandlerJob.PassThroughHandlerJob finished
答案 0 :(得分:1)
对于此特定任务,您应该能够使用grep;
$ grep PassThroughHandlerJob: log.txt
PassThroughHandlerJob: 2299 succeeded, 0 failed, 0 pending 2014-07-10 22:28:21,859 INFO
答案 1 :(得分:1)
你可以:
egrep -o 'PassThroughHandlerJob:\s+[0-9]+ succeeded, [0-9]+ failed, [0-9]+ pending' file
或者只是正常grep
:
grep -o 'PassThroughHandlerJob:[[:space:]]\+[0-9]\+ succeeded, [0-9]\+ failed, [0-9]\+ pending' file