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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete lines prior to a specific date in a log file.
# 1  
Old 04-06-2009
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


# 2  
Old 04-06-2009
so basically you want to keep the data after Jun 3 right??
if so you can use
Code:
sed -n '/Jun 3/,$p' logfile > newlog

if you have -i option in your sed man page use
Code:
sed -n -i '/Jun 3/,$p' logfile

# 3  
Old 04-06-2009
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!
# 4  
Old 04-06-2009
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
# 5  
Old 04-06-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

2. Shell Programming and Scripting

Delete specific lines from files based on another file

I have some text files in a folder named ff as follows. I need to delete the lines (in-place editing)in these files based on another file aa.txt. 32bm.txt: 249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9 250... (2 Replies)
Discussion started by: aden
2 Replies

3. Shell Programming and Scripting

Grep all lines for a specific date in log-files

I need to grep all lines for "yesterday" in /var/log/messages. Dates are in the format "YYYY-MM-DD". (5 Replies)
Discussion started by: Padmanabhan
5 Replies

4. UNIX for Dummies Questions & Answers

How to delete specific lines (2n+3 line, n=0,1,2...296) in a file?

Dear everyone, I have a file with 900 lines (there is only numbers in one line, no string), I only need the lines 2+3n (n=0,1...296), i.e line 2, 5, 8, 11...888. I tried google but only the results such as how to delete all the odd lines or all the even lines with 'awk' command. Thanks in... (4 Replies)
Discussion started by: phamnu
4 Replies

5. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

6. Shell Programming and Scripting

Delete file with specific date

let say i have list of file PermissionsDirectoriesGroupSizeDateDirectory or file drwx------2users4096Nov 2 19:51mailv drwxr-s---35www 32768Jan 20 22:39public_htmlt drwx------ 2 users 4096 Nov 2 19:51 mail drwxr-s--- 35 www 32768 Jan 20 22:39 public_html drwxr-s--- 35 www 32768 Jan... (3 Replies)
Discussion started by: Jewel
3 Replies

7. Shell Programming and Scripting

Delete lines in a file by date on the line

Hi I have a file with lines ending with a date in format dd/mm/yyyy see example below: a|b|c|08/01/2011 d|a|e|31/11/2010 e|d|f|20/11/2010 f|s|r|18/01/2011 What I would like to do is delete all lines with a date older than 30 days. With above example I should be left with a file... (5 Replies)
Discussion started by: fas1
5 Replies

8. Shell Programming and Scripting

how to delete lines from a file which starts with a specific pattern

I need to delete those lines from a file, which starts with 45. How to do it? (3 Replies)
Discussion started by: mady135
3 Replies

9. Shell Programming and Scripting

Delete specific lines from a file

Hi, I have a file ( all_users.ldif ) of the following format: cn=orcladmin, cn=Users, dc=maximus,dc=com cn=PUBLIC, cn=Users, dc=maximus,dc=com cn=portal,cn=users,dc=maximus,dc=com cn=portal_admin,cn=users,dc=maximus,dc=com cn=uddi_publisher,cn=Users,dc=maximus,dc=com... (4 Replies)
Discussion started by: itzz.me
4 Replies

10. Programming

Delete specific lines in a text file

Hi, experts, I would like to create a function that can calculate the total number of lines in a saved text file and delete specific lines in that particular file (I only want the last few lines). Hav anybody have the experience and giv me a hand in this? (9 Replies)
Discussion started by: dniz
9 Replies
Login or Register to Ask a Question