Deleting specific lines in a file

Hello,

I have a file filled with dates, such as:

04-08-2011 message
04-08-2011 message
03-08-2011 message
01-08-2011 message
31-07-2011 message
24-07-2011 message
15-07-2011 message
13-12-2008 message
26-11-2007 message

And I want to delete those lines whose date is older than 10 days.

Someway like "find ... -mtime +10 rm{}..." but relating to the lines in a file...

Ah, it should be under "AIX"

Thank you

perl '-MPOSIX qw(strftime)' -nle'BEGIN {
  $dt = strftime "%Y%m%d", localtime time - 86400 * shift;
  }
 (join "", (split /[\s-]+/)[2,1,0]) >= $dt and print   
  ' 10 infile

The above command will print the remaining lines on the standard output.
If you want to modify your existing file:

perl -i.bck '-MPOSIX qw(strftime)' -nle'BEGIN {
  $dt = strftime "%Y%m%d", localtime time - 86400 * shift;
  }
 (join "", (split /[\s-]+/)[2,1,0]) >= $dt and print   
  ' 10 infile  

Nice!

But it does not remove the lines, it just print them.
Is it possible to do it in ksh?

Thank you

I've updated my previous post.

Okay,

thank you. I would like to have in ksh but it's a good workaround for the moment in perl.

You could do it in pure Korn Shell easily if you have a recent version of ksh93 that support the following syntax:

ksh-JM 93u 2011-02-08$ print -f  '%(%Y%m%d)T\n' '10 days ago'
20110725

Alternatively you could use the datecalc script by Perderabo.