LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Display lines of two date range from syslog file (https://www.linuxquestions.org/questions/programming-9/display-lines-of-two-date-range-from-syslog-file-4175468164/)

p2006.prashant 07-02-2013 08:18 AM

Display lines of two date range from syslog file
 
Hi Guys,

I want to display lines from Solaris syslog file but with 2 dates range. I have some similar solution (http://www.unix.com/shell-programmin...2-dates-4.html) which works fine but as you know syslog has different date format (Jan 22) so this is not running in such format.

Can somebody help me in this please?

druuna 07-02-2013 08:27 AM

The link provided doesn't work.

Are you looking for something like this:
Code:

sed -n '/Jul  2 09:28:23/,/Jul  2 09:40:01/p' syslog

p2006.prashant 07-03-2013 12:19 AM

Quote:

Originally Posted by druuna (Post 4982505)
The link provided doesn't work.

Are you looking for something like this:
Code:

sed -n '/Jul  2 09:28:23/,/Jul  2 09:40:01/p' syslog

Yes.I am looking for such format but it doesn't work at my shell.

druuna 07-03-2013 02:31 AM

Quote:

Originally Posted by p2006.prashant (Post 4983091)
Yes.I am looking for such format but it doesn't work at my shell.

It doesn't work?

We cannot help you if you don't give us any information.

Also: What about the link you posted, can you fix that so we can have a look at what it is you are referring to.

David the H. 07-03-2013 04:17 PM

One problem with lines like the sed one above is that it can only match exact times. But what if you want everything from 2pm to 4pm say, but the first entry is 2:01pm? You need to be able to make relative matches.

Gnu awk has a selection of time functions that can make this kind of thing easier, but it still requires a bit of work:

http://www.gnu.org/software/gawk/man...-Functions.htm

There are also solutions using perl and other languages. I'm sure you can find lots of info on the net if you look.

Finally, there are various tools others have written. The date utilities here include one called dgrep that's designed just for this kind of thing:

http://www.fresse.org/dateutils/


All times are GMT -5. The time now is 07:17 PM.