Compare and eliminate

Could any one help me to compare the date value say at 10th column with sysdate (i.e current date) and if diffrence is more than 50 days then filter them out from the file. The file contain 10000 records.

head file

 
00971502657744      A671FAHP2EW8BG1369172011HRWS   contact information                  2010-12-30 2010-12-30          
8500411188          S561FAHP2EW8BG1400762011QIJW   contact information                  2010-12-30 2011-01-01          
0505801003          S871FAHP2EW8BG1401572011MSNL   contact information                  2010-12-29 2010-12-30          
821198238127        K981FAHP2EW9BG1171772011FORD   Secret data                          2010-12-31 2010-12-31          
821094025539        K341FAHP2EW9BG1189922011QAQO   Secret data                          2011-01-02 2011-01-02          
0551088849          S341FAHP2EW9BG1401182011NIAS   contact information                  2010-12-30 2011-01-01      
 

which one is column 10?

Last but one is 10th column.

2010-12-30
2010-12-30
2010-12-29
2010-12-31
2011-01-02
2010-12-30

GNU awk

awk 'BEGIN{
  numdays =  86400 * 5
  now=systime()
}
{
  m=split($(NF-1),a,"-")
  yr=a[1]
  mth=a[2]
  day=a[3]
  t1=mktime(yr" "mth" "day" "00" "00" "00)
  if ( (now - t1) > numdays) {
   print
  }
}' file

If Perl is ok:

#!/usr/bin/perl

use strict;
use Time::Local;

sub diffT {
   my ($segIni,$minIni,$hourIni,$dayMonthIni,$monthIni,$yearIni)=@_;
   $monthIni-=1;

   my $begin = timelocal($segIni,$minIni,$hourIni,$dayMonthIni,$monthIni,$yearIni);
   my ($seg, $min, $hours, $dayMonth, $month, $year, $dayWeek, $dayYear, $save) = localtime();
   $year+=1900;

   my $final = timelocal($seg,$min,$hours,$dayMonth,$month,$year);
   my $diffSeg = $final - $begin;

   $diffSeg;
   }
 
open(DAT,shift) or die "Unable to open file \n";

while (<DAT>) {
   chomp;
   /.+(\d\d\d\d)-(\d\d)-(\d\d)\s*$/;
   print $_ . "\n" if ( int(&diffT(0,0,0,$3,$2,$1)/(24*60*60)) > 50 );
   
   }
close (DAT);

Usage:

script.pl infile

Thanks for your update. Could you please explain bit more on this cmd? While executing above cmd am getting ^ syntax error message.

may be this may help

$5 is the column to compared from ur file

awk -vD=$(date -d '-50 days' '+%Y-%m-%d') '{if($5>D) print $0}' infile

This gives the lines with date from last 50 days