Just for fun
$ paste -sd+ file | dc -e2k0 -f- -e+3/p
.71
Here we're using the dc
reverse Polish calculator: to sum the numbers we want to write them as
1.0 0.46 + 0.67 +
however it's easier to prime the stack with zero (-e0
) and make it
0 1.0+0.46+0.67 +
since the body of the sum can then be generated by a simple paste command
:
$ paste -sd+ file
1.0+0.46+0.67
Lastly we need the final postfix +
for the sum and the postfix division which we can write in another -e
command (not forgetting to print the final result) as -e+3/p
.
The last wrinkle is that although dc
can work in arbitrary precision, division defaults to a precision of 0 and hence will return an integer result. We can change that using the 2k
command which pushes 2
to the stack and then pops it and uses the result to set the precision.
Putting it all together:
paste -sd+ file | dc -e2k0 -f- -e+3/p