SED/AWK Script to clear log file using timestamp?


 
Thread Tools Search this Thread
Operating Systems Linux SED/AWK Script to clear log file using timestamp?
# 1  
Old 03-03-2008
SED/AWK Script to clear log file using timestamp?

I have a log file on our system which fills up with lines that have been timestamped, as follows....

[03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500
[03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500
[03/03/2008 10:56:07:003] (ERROR) balance: continuing session to genapp02 : 18500
[03/03/2008 10:56:07:032] (ERROR) balance: continuing session to genapp02 : 18500
[03/03/2008 10:56:07:048] (ERROR) balance: continuing session to genapp03 : 18501

Is it possible to delete all lines in this file that are older than 28 days using SED/AWK in a script?Smilie
# 2  
Old 03-03-2008
yes, that's possible. but why not rotate the log file on daily/weekly/monthly basis?
# 3  
Old 03-03-2008
Quote:
Originally Posted by Yogesh Sawant
yes, that's possible. but why not rotate the log file on daily/weekly/monthly basis?
Ok, how would i go about that (search isn't helping me much!), and can i use logrotate without installing any extra code?

All i am aiming to do is stop the log file becoming huge and filling the box, but to keep at least 1 months worth of data for any problem solving. So i'm open to suggestions really.

Thanks for the help!

Dave
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script Closest Timestamp (LOG FILE)

Hi All, I need something where I could take the date from FILE1 and in this case the date is Thu Sep 10 13:48:42 EDT 2015 and I need it to match the closest PREVIOUS date in the log file FILE2 this means in this specific case it would be Thu Sep 10 2015 13:35:28. I only need the closest... (3 Replies)
Discussion started by: roberto999
3 Replies

2. Shell Programming and Scripting

Help on Log File format using sed or awk

Hello Gurus, First, i would like to know is there any way to solve my problem. i have a log file like this: INFO - ABCDRequest :: processing started for the record <0> TransactionNo <Txn#1> recordID <recID#1> INFO - ABCDRequest :: processing started for the record <0> TransactionNo... (9 Replies)
Discussion started by: VasuKukkapalli
9 Replies

3. Shell Programming and Scripting

sed finds nothing but it changes file's timestamp

I must go through some files to change a certain string within text files to another string. I use openSUSE and folders are mounted by cifs. Text to be replaced (only in .m extension) is U:\FOLDER and new string is N: That works fine with spaces in directory names etc., but this process ... (5 Replies)
Discussion started by: Pappa41
5 Replies

4. Shell Programming and Scripting

Using SED/AWK to Summarize Log File in 10min Intervals

I have this huge log file on my linux box that gets generated every day. I'm able to extract the information I need; however I really would like it to be broken down every 10mins. Log File Snippet 01:23:45 MARYHADA Maryhadalittle.lamb(): fleece as white as snow 1394 for and everywhere that... (8 Replies)
Discussion started by: ravzter
8 Replies

5. Shell Programming and Scripting

Fix timestamp with Sed or Awk

Hi I am dealing with the following string: Date: Thur, 13 March 2011 01:01:10 +0000 I asked for help in another topic that converted a similar string: Date: Thur, 13 March 2011 9:50 AM To a 24 hr standard. The problem is that it comes out as: Date: Thur, 13 March 2011 9:50:00 +0000... (4 Replies)
Discussion started by: duonut
4 Replies

6. Shell Programming and Scripting

Delete log file entries based on the Date/Timestamp within log file

If a log file is in the following format 28-Jul-10 ::: Log message 28-Jul-10 ::: Log message 29-Jul-10 ::: Log message 30-Jul-10 ::: Log message 31-Jul-10 ::: Log message 31-Jul-10 ::: Log message 1-Aug-10 ::: Log message 1-Aug-10 ::: Log message 2-Aug-10 ::: Log message 2-Aug-10 :::... (3 Replies)
Discussion started by: vikram3.r
3 Replies

7. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

8. UNIX for Advanced & Expert Users

WEB Server Log File Analysis using awk/sed/grep

I'm trying to find a way to show large page sizes (page size in K) from multiple web server log files. Essentially I want to show only rows from a file where a specific column is larger than some value. Has anyone ever done this type of log analysis? If so, a snippet of code would be very... (2 Replies)
Discussion started by: mike_cataldo@ad
2 Replies

9. Shell Programming and Scripting

Clear Case, Awk and script

Hello. I should have asked this awhile ago but here is my situation. My task is to generate LOC for different directories. I have a text file that has dates in this format (01-Aug-2006). My task is to read each line and compare it to a branch date. Depending on the date, it should generate a... (0 Replies)
Discussion started by: mastachef
0 Replies

10. UNIX for Advanced & Expert Users

Clear log file in use.

Hai, I have a program which updates the result in a log file, as the program runs 24*7,the size of log file keeps on increasing. Can you help me with a shell command which will clear the content of a log file in use. 1) I tried tail -10 logfile > logfile ( the content is not changed ) 2) >... (10 Replies)
Discussion started by: coolbhai
10 Replies
Login or Register to Ask a Question