How do you sum a column in Unix?

How do you sum a column in Unix?
Answer
$ sed ‘s/,/+/g’ file | bc 2.
Simply print the sum
of all the fields. Since we have 3 fields, the sum of $1, $2 and $3 gives the sum of all the numbers of the line.
 

Tìm kiếm

Back
Top