我想在两个日期之间提取日志消息。问题是日期格式如下。
[tthangavel@localhost test]$ cat file
May 1 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
May 12 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
May 13 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
May 14 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,762,10000000000,96,17805577,4979448,13233936,0,-,17559
May 15 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,848,10000000000,96,19767812,5691888,14387304,0,-,17559
Jun 10 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
Jun 11 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
Jun 15 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,762,10000000000,96,17805577,4979448,13233936,0,-,17559
Jul 10 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
Jul 14 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,848,10000000000,96,19767812,5691888,14387304,0,-,17559
Jul 15 06:00:06 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,968,10000000000,96,20602499,4746960,20327184,0,-,17559
我尝试了下面的内容,但收到了错误。
[tthangavel@localhost test]$ cat file | awk -vBegin=$(date -d"Jun 14 05:39:00" +%s) 'system("date -d\"$1 $2 $3\" +%s") > Begin {print $0}'
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
答案 0 :(得分:2)
如果日志文件中的行按日期排序(很可能), sed 将很好地完成工作
$ begin='May 12'; end='Jun 15'
$ sed -ne "/^$begin/,/^$end/p" input