Delete old date entries from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete old date entries from a file
# 1  
Old 01-19-2011
Question Delete old date entries from a file

Hello,

I have following log file.
alog.log
Oct 8 xxxxx
Oct 9 xxxxx
Oct 10 xxxxx
Nov 8 xxxxx
Nov 8 xxxxx
.
.
.
Jan 8 xxxxx

I need to delete all the lines which are having date entries older than 60 days. So If the current date is Jan 9 2011 then it should delete all the lines upto Nov 8 entry. I am writing ksh script for this.

Need some assistance...

Thanks

Last edited by Ravin83; 01-19-2011 at 04:47 AM.. Reason: Mentioning script file type
# 2  
Old 01-19-2011
sh inputfile
Code:
#! /bin/bash

declare -i now
declare -i seconds
declare -i delta
declare -i time

touch temp

time=1*24*3600  #one day before
now=`date --date="today" +%s`
while read month day anything;do
	seconds=`date --date="$month $day 2011" +%s`
	let "delta=$now-$seconds"

	if [ ! $delta -gt $time ];then
		echo $month $day $anything >> temp
	fi
done < "$1"

mv temp "$1"

This User Gave Thanks to homeboy For This Post:
# 3  
Old 01-19-2011
@homeboy

I am working on generic code and not only for 2011 year. Basically I want to delete any entries which are older than 60 days in a file.

Can you pls explain how to use "alog.log" file with this script.

I am new in this form of technology.
# 4  
Old 01-19-2011
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and delete file previous to some date

Hello All, I have a directory containing of many .dat file, but with different naming conventions. I want to delete files which are created before and on 10th September 2013. I tried this command to see files which are are the files created before 10th September find path/to/file -type... (6 Replies)
Discussion started by: nnani
6 Replies

2. Red Hat

Logrotate to delete file which has date stamp

Hello, can someone please suggest how to create an logrotate for this scenario. Need to delete all log file which are created more than 30 days ago, and all the log file have date stamp on it. I dont want to create a cron job for this task. here is the example -rw-r--r-- 1 tomcat tomcat ... (2 Replies)
Discussion started by: bobby320
2 Replies

3. 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

4. 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

5. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

6. 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

7. 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

8. Shell Programming and Scripting

delete file by date

Hello everyone, I have a folder with many files.the script (csh) runs daily and adds a new file to the folder.I need to delete the first file added that month so I will have only 30 files left every day. Thanks. (6 Replies)
Discussion started by: offerbukra
6 Replies

9. UNIX for Advanced & Expert Users

Delete File Based On Date

Hi Xpert Out There I have a lots of file in this path : -rw-r----- 1 oracle dba 3954176 Dec 21 2006 1_2008.dbf -rw-r----- 1 oracle dba 887808 Dec 21 2006 1_2009.dbf -rw-r----- 1 oracle dba 143872 Dec 21 2006 1_2010.dbf -rw-r----- 1 oracle dba ... (3 Replies)
Discussion started by: adzuanamir
3 Replies

10. Filesystems, Disks and Memory

Delete file by date or by size

Hi Everyone, This forum has been a great help to me as a new newbie in Unix. Thanks to you all. My ? now is I have a log file that help me keep track of errors within my program. But the size of the log file keeps growing and I am wondering if there is any command that will help me to... (1 Reply)
Discussion started by: odogbolu98
1 Replies
Login or Register to Ask a Question