LinuxQuestions.org
Help answer threads with 0 replies.
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 05-31-2012, 06:13 AM   #1
snoopcd
LQ Newbie
 
Registered: May 2012
Location: London
Distribution: Fedora 16
Posts: 4

Rep: Reputation: Disabled
select between 2 timestamp


hi all,
i am using both of these time stamp format
i want to select between 2 time stamp, could you please how to do that for both time format


1- time stamp format
Code:
**** Error      Thu May 31 10:55:16 GMT 2012
2- secand time stamp format
Code:
####<May 31, 2012 11:12:14 AM GMT>
 
Old 05-31-2012, 06:53 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
"Do that" where? With what? In what situation? In what language?

Please read How To Ask Questions The Smart Way, and then explain what you want to do in detail.
 
Old 05-31-2012, 07:28 AM   #3
snoopcd
LQ Newbie
 
Registered: May 2012
Location: London
Distribution: Fedora 16
Posts: 4

Original Poster
Rep: Reputation: Disabled
i want to select part of log between 2 specific time stamp using the first time format and using the secand time format
using awk - sed - grep - perl i am using redhat enterprise 6

Last edited by snoopcd; 05-31-2012 at 07:36 AM.
 
Old 05-31-2012, 09:15 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
it doesn't have unix epoch timestamp in the log file does it?

You can convert a date like so:



Code:
$ date  -d "May 31 2012 11:12:14 AM GMT" +%s 
1338462734
which will make life easier.
 
Old 06-01-2012, 05:26 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Your question is still a bit unclear. Are there two different formats inside a single log? Or are you trying to extract info from two different logs, with different timestamps? I'm guessing the latter, but how about giving us an actual example of the input and desired output?


In any case, tools like grep and sed are very limited in this kind of situation, as they can only match exact text strings (and regex variations thereof). So you'd need to enter at least part of the timestamp exactly. That is, if you want to get everything starting from, say, "May 31 2012 7:30:00", and the only entries in the log are "May 31 2012 7:29:59" and "May 31 2012 7:40:01", sed probably won't find anything. You'll need to use something more complex that can compare relative times.


Since you mention perl, I wouldn't doubt there's a perl module out there ready made for parsing logs, so I recommend searching cpan.org for what they have on offer.


gnu awk also has a set of built-in time manipulation functions. It should be possible to build a decent awk script using them. Here's the documentation for them:

http://www.gnu.org/software/gawk/man...Functions.html


Finally, there was also a poster here recently who offered up a package of tools he's written called dateutils, one of which, dgrep, can extract lines of text based on relative timestamps.

http://hroptatyr.github.com/dateutils/
 
  


Reply


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
timestamp anaik100 Linux - General 7 11-15-2006 08:56 AM
Timestamp ancys Programming 5 08-07-2006 09:21 AM
timestamp cj24900 Linux - General 7 03-17-2006 12:05 PM
Timestamp Help jch02140 Linux - Newbie 7 03-17-2006 02:33 AM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration