floating point addition

hi, :slight_smile:
I have a file like this
10.456
123.567
456.876
234.987
........
.......

What i want to do is ia have to add all those numbers and put the result in some other file.

Any help pls.

cheers
RRK

awk ' { num += $0 } END { printf("%f",num) }' file

or

echo $(tr '\n' '+' < file)"0" | bc

Hi,
When i use the following command,I am getting the following error.
echo $(tr '\n' '+' < numbers "0" ) | bc
error:Parsing error. :confused:
any help

cheers
RRK

String "0" should be outside $(...)

echo $(tr '\n' '+' < numbers )"0"  | bc
$(tr '\n' '+' < numbers )

will give output like this
For ex:

10.456+123.567+456.876+234.987+

To make above work ,add 0 to the above expression

hi,
I used the following command
echo $(tr '\n' '+' < numbers )"0" | bc
But now also it is giving the same error-"Parse error".

cheers
RRK

Can you show the output of echo $(tr '\n' '+' < numbers )"0" ?

yes,here is the output :
10.45+11.34+12.87+13.45+14.45++0

Remove the last blank line in the file

Ok, :slight_smile:
Now its working fine.
Thank u .

cheers
RRK