awk script

Anyone help me to write me a script using awk.

I have a flat file in file1, wherein I want to replace the 3rd field value of the file1. Below is the content of file1 and file 2, The output should create a file3 wherein the 3rd field already replace

File 1

ABC,AAA,A_12345,Joan
DCF,BBB,B_67890,Bryan

File 2 (lookup /reference)
A_12345 11111
B_67890 22222

Outfile (File3) should be

ABC,AAA,11111,Joan
DCF,BBB,22222,Bryan

Appreciate it a lot

Thanks

awk -v OFS="," '
NR==FNR { v[$1]=$2 ; next }
FS=","  { $3=v[$3] ; print }
    ' f2.dat f1.dat > file3.dat

Jean-Pierre.

> cat f1
A_12345 11111
B_67890 22222
> cat f2
ABC,AAA,A_12345,Joan
DCF,BBB,B_67890,Bryan
> awk 'NR==FNR{a[$1]=$2;next}$3=a[$3]' FS="( )|(,)" OFS=',' f1 f2
ABC,AAA,11111,Joan
DCF,BBB,22222,Bryan

thanks a lot

sed 's/ /,/' b > b.t
nawk 'BEGIN{FS=","}
{
if(NR==FNR)
	t[$1]=$2
else
	print $1","$2","t[$3]","$4
}' b.t a
rm b.t