In bash, I am trying to read a log file and print only lines with a timestamp between two specific times. Time format: hh: mm: ss. For example, I would look for lines that will fall between 12:52:33 to 12:59:33.
I want to use regex because I can use it in grep function.
Each log in begins with some_nr 2014-05-15 21:58:00,000000 rest_of_line .
My solution gives me lines with an edge of 1 min. I cut out ss and took all the lines with hh:mm:[0-9]{2} . $ 2 has the format filename_hh:mm:; for example: "24249_16:05:;24249_16:05:;24249_16:07:;24249_16:07:;24249_16:08:"
My code is:
B=$2 for line in ${B//;/ } ; do TENT=`echo $line | awk '{split($0,numbers,"_"); print numbers[1]}'`"_logs.txt" TIME=`echo $line | awk '{split($0,numbers,"_"); print numbers[2]}'`"[0-9]{2}" grep -iE ${TIME} ${TENT} >> ${FILE1} done
I need a solution with an edge of 15 seconds at any time, not 60. I want to have input in the format filename_hh:mm:ss and take the lines for hh: mm: ss +/- 15s or filename_hh:mm:ss(1)_hh:mm:ss(2) and take the lines between hh: mm: ss (1) and hh: mm: ss (2). For some time there are no lines, so the solution should “recognize” if it sometimes coincides with the entered interval or not.
The log files are as follows:
1002143 1002143 2014/15/05 22:09:52.937004 bla 1002130 2014/15/05 22:09:44.786002 bla bla 1001667 2014/15/05 22:09:44.592009 bl a bla 1001667 1001667 2014/15/05 22:09:44.592009 bl a bla
source share