How to extract logs between two time stamps, line may or may not start with datetime.
I am trying below and it is only extracting the lines that starts with datetime only. Datetime format is 2014-04-07 23:00
$ awk \
'$0 ~ /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-2][0-9]:[0-5][0-9]/
{
if ($1" "$2 >= "2014-04-07 23:00") p=1;
if ($1" "$2 >= "2014-04-08 02:00") p=0;
}
p { print $0 }' log
Here is my sample data:
2014-04-07 22:59:10.001 agaggagag
gagagg
2014-04-07 23:40:33.345 aegsgssdh
wqtqttqtqtq
post
agggsdgg
2014-04-08 01:00:54.777 ggsdgwettwetewt
cvdgwetegdkiytitityi
error
2014-04-08 02:02:22.009 qwwqtwtwebbcbewdhshsdh
asgsaftewtewt
1253536443755475
2014-04-08 10:55:34.934 etwtewtewppip
jklhlljkjvncncmmm
sghywywywywyw
I want to extract all data between 2014-04-07 23:00
and 2014-04-08 02:00