2 回答
TA贡献1856条经验 获得超5个赞
$ date
Sat, May 05, 2018 10:49:13 AM
$ cat tst.awk
{
split($4,t,/[[ :\/]/)
mthNr = sprintf("%02d",(index("JanFebMarAprMayJunJulAugSepOctNovDec",t[3])+2)/3)
curTime = t[4] mthNr t[2] t[5] t[6] t[7]
}
curTime >= minTime
$ awk -v minTime=$(date -d '60 min ago' '+%Y%m%d%H%M%S') -f tst.awk file
66.249.93.30 - - [05/May/2018:11:00:21 +0200] Second Line
66.249.93.30 - - [05/May/2018:11:15:39 +0200] Third Line
66.249.93.30 - - [05/May/2018:12:00:11 +0200] Fourth Line
使用问题的时间来获得问题的预期输出:
$ awk -v minTime=$(date -d '2018/05/05 11:01:06' '+%Y%m%d%H%M%S') -f tst.awk file
66.249.93.30 - - [05/May/2018:11:15:39 +0200] Third Line
66.249.93.30 - - [05/May/2018:12:00:11 +0200] Fourth Line
- 2 回答
- 0 关注
- 258 浏览
添加回答
举报