make a sum in the awk command
by Drosera_capensis from LinuxQuestions.org on (#52P9N)
Hello everyone,
I would like to make the ratio of all the 50 numbers that are in a column of a file. So, the ratio version of a column of numbers.
The ratio would be equal to row value / sum of all the column.
Code:for f in {1..50};
do
cat file | awk ' {sum += $1} {a = $1; b = sum; print (a/b)}' ;
doneBut the sum given by the first part of the awk command is the sum of the row already processed, and not the sum of the 50 rows of the document.
Would anyone know how to make the sum of all the rows of the documents at any loop?
Thanks for the help!


I would like to make the ratio of all the 50 numbers that are in a column of a file. So, the ratio version of a column of numbers.
The ratio would be equal to row value / sum of all the column.
Code:for f in {1..50};
do
cat file | awk ' {sum += $1} {a = $1; b = sum; print (a/b)}' ;
doneBut the sum given by the first part of the awk command is the sum of the row already processed, and not the sum of the 50 rows of the document.
Would anyone know how to make the sum of all the rows of the documents at any loop?
Thanks for the help!