LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash - question about grepping a specific time period (https://www.linuxquestions.org/questions/programming-9/bash-question-about-grepping-a-specific-time-period-825050/)

xmichielx 08-09-2010 05:19 AM

bash - question about grepping a specific time period
 
Hello,

I am fairly new to bash and have a question how I can accomplish the following:
I have to grep in a logfile for a specific time period and print it out.
For example: someone wants to get all results from a logfile from 21:05-21:10

How do print/grep that period?
An example begin of a log entry: 2010-08-04 00:00:01,774 ERROR

Thanks for any help.

druuna 08-09-2010 06:23 AM

Hi,

In general: grep "2010-08-04 00:00:01" logfile

If you want this range: 21:05-21:10 -> grep "21:0[5-9]" logfile
The above example looks for the range 21:05:00 -> 21:09:59. The [5-9] part tells grep to look for everything from 5 t 9 (including both 5 and 9).

Hope this helps.

xmichielx 08-17-2010 05:55 AM

Hello,

Thanks that did the trick for me, I was using a loop but your example is lesser code and works perfectly :)

Thanks!

Michiel

druuna 08-17-2010 06:05 AM

You're welcome :)

PhamTheThao 04-08-2015 12:34 AM

Quote:

this range: 21:05-21:10 -> grep "21:0[5-9]" logfile
If i want this range: 21:05 - 21:23 - how to grep?

NevemTeve 04-08-2015 12:44 AM

Write a small program in awk/perl/php/whatever


All times are GMT -5. The time now is 04:30 AM.