Using any awk in any shell on every Unix box and without creating new fields in each record (which is inefficient as it causes awk to re-build the record every time you change a field) and without updating the input record (which is inefficient as it causes awk to re-split the record into fields every time you change the record) and designed to work for any number of value input columns in any order:
$ cat tst.awk
BEGIN { FS=OFS="\t" }
{ printf "%s%s", $0, OFS }
NR==1 {
for (i=3; i<=NF; i++) {
printf "Total_%s%s", $i, OFS
tags[i] = $i
}
print "Percentage"
next
}
{
delete tot
for (i=3; i<=NF; i++) {
tag = tags[i]
n = split($i,vals,",")
for (j in vals) {
tot[tag] += vals[j]
}
printf "%s%s", tot[tag], OFS
}
printf "%0.3f%s", (tot["Weight"] ? tot["Height"] / tot["Weight"] : 0), ORS
}
$ awk -f tst.awk file
Name type Age Weight Height Total_Age Total_Weight Total_Height Percentage
Xxx M 12,34,23 50,30,60,70 4,5,6,5.5 69 210 20.5 0.098
Yxx F 21,14,32 40,50,20,40 3,4,5,5.5 67 150 17.5 0.117
$ awk -f tst.awk file | column -t
Name type Age Weight Height Total_Age Total_Weight Total_Height Percentage
Xxx M 12,34,23 50,30,60,70 4,5,6,5.5 69 210 20.5 0.098
Yxx F 21,14,32 40,50,20,40 3,4,5,5.5 67 150 17.5 0.117
To show the functional advantages of the above approach, imagine you need to add more values like ShoeSize and/or rearrange the order of the columns, e.g.:
$ column -t file
Name type ShoeSize Height Age Weight
Xxx M 12,8,10 4,5,6,5.5 12,34,23 50,30,60,70
Yxx F 9,7,8 3,4,5,5.5 21,14,32 40,50,20,40
Now run the above script and notice you get Total_ columns added for every original column and you still get the same Percentage column of Height/Weight added to the end:
$ awk -f tst.awk file | column -t
Name type ShoeSize Height Age Weight Total_ShoeSize Total_Height Total_Age Total_Weight Percentage
Xxx M 12,8,10 4,5,6,5.5 12,34,23 50,30,60,70 30 20.5 69 210 0.098
Yxx F 9,7,8 3,4,5,5.5 21,14,32 40,50,20,40 24 17.5 67 150 0.117