Delete lines prior to a specific date in a log file.

Hi all.

I have a database log file in which log data get appended to it daily. I want to do a automatic maintainence of this log by going through the log and deleting lines belonging to a certain date.

How should i do it? Please help. Thanks.

Example. To delete all lines prior to Jun 3.

My content of my log is like below:
Sun Jun 1 01:38:25 2008
Completed: ALTER DATABASE OPEN
Sun Jun 1 22:00:40 2008
Thread 1 advanced to log sequence 2518
Current log# 1 seq# 2518 mem# 0: /u03/oradata/sbdevdb/redo01.log
Current log# 1 seq# 2518 mem# 1: /u03/oradata/sbdevdb/redo04.log
Mon Jun 2 10:00:33 2008
Thread 1 advanced to log sequence 2519
Current log# 2 seq# 2519 mem# 0: /u04/oradata/sbdevdb/redo02.log
Current log# 2 seq# 2519 mem# 1: /u04/oradata/sbdevdb/redo05.log
Mon Jun 2 22:01:10 2008
Thread 1 advanced to log sequence 2520
Current log# 3 seq# 2520 mem# 0: /u05/oradata/sbdevdb/redo03.log
Current log# 3 seq# 2520 mem# 1: /u05/oradata/sbdevdb/redo06.log
Tue Jun 3 01:30:03 2008
Starting background process EMN0
EMN0 started with pid=20, OS id=639158
Tue Jun 3 01:30:03 2008
Shutting down instance: further logons disabled
Tue Jun 3 01:30:03 2008

so basically you want to keep the data after Jun 3 right??
if so you can use

sed -n '/Jun 3/,$p' logfile > newlog

if you have -i option in your sed man page use

sed -n -i '/Jun 3/,$p' logfile

Hi. Thanks for the reply.

I tried and it did work to extract all logs after Jan 1. But I want the data from Jan 1 to remain in the original file. The command seems to only be able to pipe the output to another filename instead.

Any other options? Thanks!

Hi,

What do you want?
Vidhyadhar reply does exactly what you are looking for.
It is printing only the data which is after june 3 and redirecting it to a new file.

Thanks
NT

Hi all.

Vidhyadhar's reply did redirect all logs after Jan 1 to a new file.

But, what i want is log data after Jan 1 to remain in my original file name. My original log filename is alert.log. I want alert.log to hold only data after Jan 1.

Thanks.