LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-09-2010, 04:19 AM   #1
xmichielx
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
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.
 
Old 08-09-2010, 05:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 08-17-2010, 04:55 AM   #3
xmichielx
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Hello,

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

Thanks!

Michiel
 
Old 08-17-2010, 05:05 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
You're welcome
 
  


Reply

Tags
bash, period, time


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable users after a specific time period hhvv Linux - General 5 12-21-2008 05:46 PM
MPlayer: Recording specific time period of audio stream nazarioz Linux - Newbie 7 06-02-2005 09:47 PM
quit program after a specific time (prob. BASH) bglnelissen Linux - General 2 01-25-2005 01:22 AM
Running a program for a specific period of time CaptainHowdy Linux - Software 2 08-22-2004 07:02 PM
Only starting command in a specific time period jeroenvrp Linux - Software 3 07-20-2004 11:18 PM


All times are GMT -5. The time now is 08:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration