Code:
awk 'FILENAME=="ROSEIN"{
if(length($2)==6){
A[$1]=$2
}
}
FILENAME=="BKUPORAGLCC20091204"{
if(A[substr($0,9,6)]){
B[substr($0,1,5),A[substr($0,9,6)]]+=substr($0,38)substr($0,21,17)
}
}
FILENAME=="rosetb.txt"{FS=",";date=$3;C[0$1,$2]=$5}
FILENAME=="roset1.txt"{FS=",";D[0$1,$2]=$4;E[0$1,$2]=$5;F[0$1,$2]=$6;G[0$1,$2]=$7}
END{
for (combined in B){
if(combined != ""){
split(combined,seperate,SUBSEP)
if(B[seperate[1],seperate[2]] ~ /-/){
{printf "%010s|%06s|%08s|%015.2f|%012d|%015.2f|%012d|%015.2f|%012d|\n",
seperate[1],seperate[2],date,B[seperate[1],seperate[2]],C[seperate[1],
seperate[2]],D[seperate[1],seperate[2]],E[seperate[1],seperate[2]],
F[seperate[1],seperate[2]],G[seperate[1],seperate[2]]}
}
else{
{printf "%010s|%06s|%08s|+%014.2f|%012d|%015.2f|%012d|%015.2f|%012d|\n",
seperate[1],seperate[2],date,B[seperate[1],seperate[2]],C[seperate[1],
seperate[2]],D[seperate[1],seperate[2]],E[seperate[1],seperate[2]],
F[seperate[1],seperate[2]],G[seperate[1],seperate[2]]}
}
}
}
}' ROSEIN BKUPORAGLCC20091204 rosetb.txt roset1.txt