The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
delete lines containing a specific word in afile sireesha9 Shell Programming and Scripting 4 02-23-2009 06:07 AM
how to display specific lines of a specific file raidkridley UNIX for Dummies Questions & Answers 2 10-15-2008 03:46 PM
How to delete specific lines at the same time zanetti321 UNIX for Advanced & Expert Users 1 03-24-2008 07:00 AM
Sed help to delete everything prior to WORD drheams Shell Programming and Scripting 2 12-09-2005 05:34 PM
Delete specific lines in a text file dniz High Level Programming 9 08-08-2005 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-06-2009
ahSher ahSher is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 10
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 (permalink)  
Old 04-06-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,418
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 (permalink)  
Old 04-06-2009
ahSher ahSher is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 10
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 (permalink)  
Old 04-06-2009
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
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 (permalink)  
Old 04-06-2009
ahSher ahSher is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 10
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0