The following data contains a variable number of fields per record with each row being a single record. Awk script that will add all of the fields for each row together and print the resulting sum per record.
rand.csv
1,3,5,8,10,11,54
1,2,3,4
15,18,21,42,37
1,1,1,0,0,3,16
4,1,8,0,4,6,13,16,17,20,8,6,4
13
This is what i wrote so far
BEGIN {
FS=","
}
{
sum = 0
for(i=1; i<=NF; i++){
sum+=$i;
}
print "Sum "$1""
}
}
END{
print "Sum of each row"
}
$1
usually refers to the first column in awk