LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-01-2012, 09:26 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Extract some part of a file with specified time period in it?


I have a log file, which contain following sample entries:
Quote:
10:45:01 This is for example
10:55:04 This is for example
11:00:00 This is for example
11:05:55 This is for example
11:06:05 This is for example
11:07:35 This is for example
11:08:45 This is for example
11:09:50 This is for example
11:11:58 This is for example
11:14:16 This is for example
11:35:34 This is for example
11:40:11 This is for example
11:58:16 This is for example
12:00:36 This is for example
12:01:04 This is for example
12:10:10 This is for example
12:16:35 This is for example
I want to extract only that part of this log file which contain entries made between 11:00 and 12:00 (i.e. for that one hour only, or for any specified period), then how can I do this?

Last edited by shivaa; 11-01-2012 at 09:29 AM.
 
Old 11-01-2012, 09:44 AM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,927

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
Code:
grep ^11
 
1 members found this post helpful.
Old 11-01-2012, 09:59 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by schneidz View Post
Code:
grep ^11
Thanks! It helped, but it will return all entries starting with 11.
The problem is how to specify a range of time, for instance, extract log entries made between 11:40 and 12:55?
And this log file's actual content contains one more column at the beginning for username, like this:
Quote:
....
jack 11:07:35 This is for example
jack 11:08:45 This is for example
smith 11:09:50 This is for example
...
...
 
Old 11-01-2012, 11:00 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 761
Blog Entries: 2

Rep: Reputation: 197Reputation: 197
awk -v t1=11:40:00 -v t2=12:55:00 '{if (($2>=t1)&&($2<=t2)){print}}' filename
 
2 members found this post helpful.
Old 11-01-2012, 11:34 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Thanks, it worked
 
  


Reply

Tags
cut, file, pattern, 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
[SOLVED] Cut the selected part of directory name kauuttt Linux - Newbie 7 07-18-2012 03:37 AM
[SOLVED] How to fetch entries in a log file for a particular period of time ? rhadmn Linux - Enterprise 3 03-19-2012 05:43 AM
cut part of a string using awk m4rtin Programming 2 09-03-2009 07:32 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM
Part of screen cut off moo-cow Ubuntu 4 05-03-2006 05:49 PM


All times are GMT -5. The time now is 10:16 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