Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 选择两个日期之间的日志消息_Bash_Logging_Awk_Sed - Fatal编程技术网

Bash 选择两个日期之间的日志消息

Bash 选择两个日期之间的日志消息,bash,logging,awk,sed,Bash,Logging,Awk,Sed,我想提取两个日期之间的日志消息。问题是日期格式如下所示 [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_proce

我想提取两个日期之间的日志消息。问题是日期格式如下所示

[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

如果日志文件中的行是按日期排序的(看起来很可能),sed将很好地完成这项工作

$ begin='May 12'; end='Jun 15'
$ sed -ne "/^$begin/,/^$end/p" input

也许你能帮忙?祝你好运,谢谢!但这需要在日志文件中显示一条确切的开始和结束日期的日志消息。在这里,如果没有日期为“5月12日”或“6月15日”的日志消息,这将不起作用