#!/usr/bin/perl
use Time::Local;
use strict;
open (VF,">valid-file") || die "$! \n";
open (IF,">Invalid-file") || die "$! \n";
while (<DATA>) {
chomp;
my @flds=split(/\|/);
eval {
timelocal(0,0,0,substr($flds[3],6,2),substr($flds[3],4,2),substr($flds[3],0,4));
};
print IF "$_\n" if ($@);
print VF "$_\n" if !($@);
}
close(VF);
close(IF);
__DATA__
9f680174-cb87|20077337254|0|20120511|N
9f680174-cb88|20077337254|0|20120534|N
most versions of awk don't have very good date-handling functions, so it'd mean rolling your own and worrying about leap years and other such mess. perl is probably the best way.
#!/bin/bash
while IFS='|' read a b c d e
do
date -d "$d" > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "$a|$b|$c|$d|$e" >> valid.txt
else
echo "$a|$b|$c|$d|$e" >> invalid.txt
fi
done < inputfile