LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Extract some part of a file with specified time period in it? (http://www.linuxquestions.org/questions/linux-newbie-8/extract-some-part-of-a-file-with-specified-time-period-in-it-4175435076/)

shivaa 11-01-2012 09:26 AM

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?

schneidz 11-01-2012 09:44 AM

Code:

grep ^11

shivaa 11-01-2012 09:59 AM

Quote:

Originally Posted by schneidz (Post 4819728)
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
...
...

linosaurusroot 11-01-2012 11:00 AM

awk -v t1=11:40:00 -v t2=12:55:00 '{if (($2>=t1)&&($2<=t2)){print}}' filename

shivaa 11-01-2012 11:34 AM

Thanks, it worked ;) ;)


All times are GMT -5. The time now is 04:26 PM.