I am so beginner with linux .
Oct 07 11:00:33 some text
Oct 07 12:00:33 some text
Oct 08 14:00:33 some text
Oct 08 21:00:33 some text
Oct 09 21:00:33 some text
I would like to grep logs between 2015-07-08 12:00:33 to 2015-07-10 21:00:31
I think I can do that with these codes that I've got from here ,
sudo awk -v start='2015-07-08 12:00:33' -v end='2015-07-10 21:00:31' '
BEGIN{ gsub(/[:-]/," ", start); gsub(/[:-]/," ", end) }
{ dt=$1" "$2; gsub(/[:-]/," ", dt) }
mktime(dt)>=mktime(start) && mktime(dt)<=mktime(end)' a.txt
I've tested it and it works perfectly when log date time format is 2015-10-09 21:00:33
but my log date time format is Oct 09 21:00:33
so I don't know How to convert it to 2015-10-09 21:00:33
2015-10-29 21:00:33
, because timestamps in such format can be parsed, sorted or compared relatively easily. It doesn't have to be this exact format. The point is some formats are better than others when it comes to parsing, sorting or comparing; use this fact. I know this comment won't solve your current problem, but it may help avoid future ones.