Compare two files A & B and accordingly modify file A

Friends,

i have two huge complex files (for eg :A & B)as output ,

the sample contents of the files are as follows :
A

ID,DATE,SUM1,SUM2,TOTAL(SUM1+2) 
A5066,20/04/2010,25000,50000,75000
A5049,20/04/2010,25000,60000,85000
 

B

ID,DATE,SUM1,SUM2,TOTAL(SUM1+2)
A5066,21/04/2010,25000,70000,95000
A5049,21/04/2010,25000,20000,45000

The above files are generated on daily basis and the problem is the printed date is calendar date.

I would like to compare the files A&B and print file C as follows :

File C :

ID,DATE,SUM1,SUM2,TOTAL(SUM1+2)
A5066,21/04/2010,25000,70000,95000
A5049,20/04/2010,25000,20000,45000

The condition is :
The date in the new file should be printed from the file (A) if the total(Column 5) in File B is less than File A

To be honest,i am confused of what command to use...I was nibbling with awk ..but couldn't go anywhere.It will be great if any suggestions or ideas can be provided.

Thanks in advance.

Try this:

awk -F, 'NR==FNR {a[$1]=$1; b[$1]=$2; c[$1]=$5; next}
a[$1] && $5 < c[$1] {$2=b[$1]}1' OFS="," A B > C

Hi Franklin...

U r great my friend...actually my file was much bigger (i.e) it contains almost 18 columns .i tried ur logic by tweaking it a little bit according to the file which i have and it works amazingly.

Thanks

The following is the snippet which is working with my file.

awk -F, 'NR==FNR {a[$1]=$1; b[$1]=$3; c[$1]=$15; next} a[$1] && $15 < c[$1] {$3=b[$1]}1' OFS=","