Replace the nth column date as MM/DD/YYYY

Hi,
I need some unix command to replace the following thing.

cat test.dat
1234|test|8/19/2009|8/20/2009|test
1234|test|8/9/2009|8/21/2009|test
1234|test|8/1/2009|8/2/2009|test

after processing

1234|test|08/19/2009|08/20/2009|test
1234|test|08/09/2009|08/21/2009|test
1234|test|08/01/2009|08/02/2009|test
awk -F"|" '
{	for(i=3;i<=4;i++)
		{
			split($i,a,"/");
			if(a[1]<10){a[1]="0"substr(a[1],1)};
			if(a[2]<10){a[2]="0"substr(a[2],1)};
			$i=a[1]"/"a[2]"/"a[3]};
			print
}' OFS="|" filename

if the file is in the below format

1234|test|8/19/2009||test
1234|test|8/9/09|8/21/2009|test
1234|test|8/1/86||test
1234|test||8/1/09|test

output..

1234|test|08/19/2009||test
1234|test|08/09/2009|08/21/2009|test
1234|test|08/01/1986||test
1234|test||08/01/2009|test

And what decides the century for years? That is, how is 86 1986 and not 2086 or 1886, etc.?

u can ignore that part.. to be precise

1234|test|8/19/2009||test
1234|test|8/9/2009|8/21/2009|test
1234|test|8/1/2009||test

output..

1234|test|08/19/2009||test
1234|test|08/09/2009|08/21/2009|test
1234|test|08/01/2009||test
nawk '{
for(i=3;i<=4;i++)
 if((n=split($i,a,"/"))==3)
  $i=sprintf("%02d/%02d/%04d",a[1],a[2],a[3])
}1' FS=\| OFS=\| infile
1 Like
awk -F"|" '
{	for(i=3;i<=4;i++)
		{
			n=split($i,a,"/");
			if(n==3) 
				{
					if(a[1]<10){a[1]="0"substr(a[1],1)};
					if(a[2]<10){a[2]="0"substr(a[2],1)};
					$i=a[1]"/"a[2]"/"a[3]
				}
		};
			print
}' OFS="|" filename