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
sh inputfile
#! /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"
1 Like
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.