Help In Calculation of large values in loop

Hi Gurus,

I am writing a shell script in which i need to strip out the numbers from file
the values are unknown i. e. the range cannot be predicted.. and in my current program the sum of values is not coming as desired i think the value of calculation is crossing the range i.e. after some addition it starts to become negative and the results are wrong.

values for e.g are as follows
302565658945
302565658945
565658945589
55658945589
56565894558912

The sum should be for all of above values.

So On..
Please help me as i have tried let, expr. and being a new shell programmer i am stuck up here.

Thanks in advance

sandeep

if you need to sum up all the numbers in the file 'myFile.txt':

echo `sed -e 's/$/+/' myFile.txt` 0 | bc

Thanks for reply

The numbers i need to pick up are decided based on certain beginning value
of a comma separated values and only for specific rows in a file, i am able to get these values stripped out in a separate file, only the calcualtion is coming wrong. Say a.txt is a file and following are the contents :

12345678912
123458785454
145645645454
4548778545487
545645
79879878978787878

I am opening this file to perform addition in loop.

Pls. comment
Sandeep

so does the proposed solution work on the the 'a.txt' file or not?
I get a value of '79884709207988830' for the posted sample a.txt

If you do your 'stripping' [no pun inteded] with 'awk', you might be able to do your additions in the same awk script with no need for the intermediate 'stripped' file.

Hi,

Thanks for your help. I will need to check it as i don't have MKS Toolkit or Linux os with me right now, I will work on your proposed solution and get back to you tomm.

Thanks
Sandeep

Your suggested solution has worked fine. Thanks a lot
Just 1 more question how can i store the output in variable instead of echo ? for same command

Thanks
Sandeep

depends on a shell. for ksh:

#!/bin/ksh

myVar=$(echo `sed -e 's/$/+/' myFile.txt` 0 | bc)
echo "myTotal -> [${myVar}]"