A pure Korn shell solution
Code:
#!/usr/bin/ksh93
typeset -L1 -u firstF
typeset -L1 -u firstL
while read a b c d e
do
if [[ $a == "totalcount" ]]; then
nameF=$b
nameL=$c
numD=$d
numE=$e
fi
if [[ $a == "total" ]]; then
firstF=$nameF
firstL=$nameL
print "${firstF}${nameF#?}, ${firstL}${nameL#?}, $b, $numD, $numE"
fi
done < file