LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 07-02-2013, 08:18 AM   #1
p2006.prashant
LQ Newbie
 
Registered: Dec 2007
Location: India
Distribution: Redhat Linux 5,6.2, Solaris
Posts: 16
Blog Entries: 1

Rep: Reputation: 5
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?
 
Old 07-02-2013, 08:27 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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
 
Old 07-03-2013, 12:19 AM   #3
p2006.prashant
LQ Newbie
 
Registered: Dec 2007
Location: India
Distribution: Redhat Linux 5,6.2, Solaris
Posts: 16

Original Poster
Blog Entries: 1

Rep: Reputation: 5
Quote:
Originally Posted by druuna View Post
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.
 
Old 07-03-2013, 02:31 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by p2006.prashant View Post
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.
 
Old 07-03-2013, 04:17 PM   #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
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/
 
  


Reply



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
SED append to a specific range of lines of a file Gener@l Programming 6 04-24-2013 06:56 PM
how to display Missing date in a file newbie_adm Programming 5 03-21-2013 06:24 PM
grep and display the below lines in file sunilsagar Programming 3 02-01-2012 09:43 AM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM

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

All times are GMT -5. The time now is 01:52 AM.

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