How to choose only lines between specific date till now?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix questions > How to choose only lines between specific date till now?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to choose only lines between specific date till now?  
T0me3


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-21-06 12:49 PM

Hello,

I have log file with entries:

2005-10-1 Server error at......
exception at
2005-10-2 Starting something
Something started
Client requested ...........
2005-10-3 Server encountered error at.....
Something happended


I would like to print only lines containing errors, but only those,
which are from 2005-10-3 or later.
How can i achieve this? grep -i -e "error" myfile.txt prints all lines
with error, but i would like to print
only lines with errors from date 2005-10-3 to today.

Thanks in advance

T0me3






[ Post a follow-up to this message ]



    Re: How to choose only lines between specific date till now?  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-06 11:11 PM

On 2006-01-21, T0me3 wrote:
> Hello,
>
> I have log file with entries:
>
> 2005-10-1 Server error at......
> exception at
> 2005-10-2 Starting something
> Something started
> Client requested ...........
> 2005-10-3 Server encountered error at.....
> Something happended
>
>
> I would like to print only lines containing errors, but only those,
> which are from 2005-10-3 or later.
> How can i achieve this? grep -i -e "error" myfile.txt prints all lines
> with error, but i would like to print
> only lines with errors from date 2005-10-3 to today.

Assuming that the lines are in chronological order:

awk '/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9]/  &
#123;
split($1,d,"-")
date = sprintf("%04d%02d%02d", d[1], d[2], d[3])
}
/error/ && date > 20051003 { print }
'

--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |          is released under the
2005, Apress                 |     GNU General Public Licence





[ Post a follow-up to this message ]



    Re: How to choose only lines between specific date till now?  
Michael Paoli


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-06 11:11 PM

T0me3 wrote:
> I have log file with entries:
>
> 2005-10-1 Server error at......
> exception at
> 2005-10-2 Starting something
> Something started
> Client requested ...........
> 2005-10-3 Server encountered error at.....
> Something happended
>
> I would like to print only lines containing errors, but only those,
> which are from 2005-10-3 or later.

If your log entries are chronological, how about something like:
sed -ne '/^2005-10-3/,${/error/p;}'

One can also make the part within {} more complex to handle, e.g.
multiple regular expressions, e.g.:
sed -ne '/^2005-10-3/,${/error/{p;n;};/fail/p;}'






[ Post a follow-up to this message ]



    Re: How to choose only lines between specific date till now?  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 07:55 AM

2006-01-21, 03:41(-08), T0me3:
> Hello,
>
> I have log file with entries:
>
> 2005-10-1 Server error at......
> exception at
> 2005-10-2 Starting something
> Something started
> Client requested ...........
> 2005-10-3 Server encountered error at.....
> Something happended
>
>
> I would like to print only lines containing errors, but only those,
> which are from 2005-10-3 or later.
> How can i achieve this? grep -i -e "error" myfile.txt prints all lines
> with error, but i would like to print
> only lines with errors from date 2005-10-3 to today.
[...]

I would suggest that you modify your application that logs those
lines so that it formats the time stamps as 2005-10-03 instead.
This way, a string comparison would be enough:

awk '
$1 "" > "2005-10-03" && /error/' < file.log


--
Stéphane





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:55 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register