Detail_Amount_Sum=0;
for i in `cat IFs_temp1.txt`
do
Detail_Amount_Sum=`echo "scale=2; $Detail_Amount_Sum + $i" | bc -l`
done
final_sum=$Detail_Amount_Sum;
but if i have one lakh record in the file it will take an hour to complete the for loop itself.
i need a command which will complet very fast but has to give accurate result.
my output should be in the scale of 2 like ( 900.00 or 900.01 or 0.01 or 3.27)
It is slow because you are running bc 9,000 times for 9,000 numbers. Transform the entire stream into something you can feed into bc directly instead -- one program instead of 9,000.
For example if you transform it into lines like a+=(-5) then follows up with the last line a it will sum them all and print the resulting value.
awk 'BEGIN { print "scale=2" } { print "a+=("$1")" } END { print "a" }' inputfile | bc
Ordinarily I would use awk to sum the numbers too, but if you need infinite precision, bc is for you.