delete record

I have a log file , that keep the record of system activities , as below , now the log is appending so that it becomes very large .

"
05/01/08 Normal userA
05/01/08 Normal userB
05/02/08 Alnormal userC
"
"
10/01/08 Normal userA
10/02/08 Normal userA
"

Now I would like to keep the log current , so if the date is over 60 days , then remove this row , like above , the first three row should be removed as 05/01/08 and 05/02/08 is over 60 days ( today is 10/08/08 ) , can advise how to do it ? thx

hi,
below one can roughly meet your desire, but you need to modify it to be correct enough.

nawk -v d="10/08/08" 'BEGIN{
	split(d,brr,"/")
}
{
	split($1,arr,"/")
	days=(brr[1]-arr[1])*30+(brr[2]-arr[2])+(brr[3]-arr[3])*365
	if(days<60)
		print
}' filename

You requirement need 2 steps.

  1. Calculate the date 61 days ago, and the way you can do that depends on your OS or your "date" version, search the forum for "date time calculation"
  2. If your "sed" support -i option you can delete from beginning until date, if not you have to look for another way.

thx ,

As you told me , it needs to modify sth, i found two thing need to be modify ,

  1. it only print the line meet the condition , how can I remove the line ?
  2. the current idate s fixed , how to change it to today ?

thx

A datafile, with dates mm/dd/yy before other text

> cat file296
05/01/08 blah
05/01/08 more blah
05/02/08 yep
06/01/08 ummmm
06/02/08 hmmmm
06/02/08 arrgggg
06/03/08 cool
07/04/08 hot hot hot
07/04/08 hooray

script that adjusts date to yy/mm/dd so can get last three (head -3) dates to keep

> cat order_file296
awk '{print substr($0,7,2)"/"substr($0,1,2)"/"substr($0,4,2)"|"substr($0,1,8)}' file296 | sort -u >file296.dte
sort -rn file296.dte | head -3 | cut -d"|" -f2 >file296.good

egrep -f file296.good file296 >file296.keep

echo "original"
cat file296
echo "keep stuff "
cat file296.keep

program execution shows the original file, and only those records that were of the last three days of entries.

> order_file296 
original
05/01/08 blah
05/01/08 more blah
05/02/08 yep
06/01/08 ummmm
06/02/08 hmmmm
06/02/08 arrgggg
06/03/08 cool
07/04/08 hot hot hot
07/04/08 hooray
keep stuff 
06/02/08 hmmmm
06/02/08 arrgggg
06/03/08 cool
07/04/08 hot hot hot
07/04/08 hooray
> 

So, this approach sort of does what you are looking to do. Depends on the data you have - if there is an entry for everyday, then this logic would be fine. Probably a couple other tweaks necessary, but I leave those to you to figure out.