在日志文件中:
...
Fri Jan 24 12:33:56 +0800 2014
11 files processed.
56471 records inserted.
Fri Jan 24 12:36:56 +0800 2014
...
...
Sat Jan 26 12:36:25 +0800 2014
13 files processed.
62471 records inserted.
Sat Jan 26 12:37:56 +0800 2014
...
我想在13
中获取特定日期13 files processed.
)的值Jan 26 2014
。如何通过命令行grep完成?
答案 0 :(得分:1)
awk解决方案:
awk '/Jan 26/{p=1;next} p{p=0;print $1}' file
13
grep only解决方案:
grep 'Jan 26' -A 1 file | grep -oP '[0-9]+(?= files processed)'
13
答案 1 :(得分:0)
其他一些awk
版本:
awk '/Jan 26/ {getline;print $1}' file
13
awk '/Jan 26/{p=NR+1} NR==p {print $1}' file
13
awk '{p--} /Jan 26/ {p=1} !p {print $1}' file
13