I have a text file that has a list of results from travel distance
Traveldistance.txt
12.1 meters
14.1 meters
Whenever I tried to compute the sum of the distance, the result will display this message
12.1
12.1
26.2
26.2
However, if I remove the word "meters" from the travel distance text file, it is able to compute perfectly, such as this
12.1
26.2
Is there any way to read in the string data and allow the distance to be computed perfectly, such as this
12.1 meters
26.2 meters
I have even tried while loop, but it did not even work. My codes are shown as below
#!/bin/bash
SUM=0;
for n in $(cat DistanceLog_TD01.txt)
do
SUM=$(echo "$SUM + $n" | bc); #Need help here
echo $SUM;
done
echo $(date +"%m-%d-%Y %T") "Total distance:" $SUM "meters" >> totaldistance.txt
Thanks!