I hope someone can help...
I've parsed integers to a file separated by carriage returns like so:
...
427562786
6834257
978539857
9742
578375
...
I wish to put these into an array and sum the total. However, after some fervent Googling, I can only find a reasonable way to do this using a for loop, which I'm on pretty good authority is not the best way to read a file line by line.
I understand that somewhere in this script I would need to declare something like this:
IFS='
'
while read line
do
array creation magic here
done < /tmp/file
SUM=0
while read line
do
SUM= sum array elements magic here
done < /tmp/file
printf $SUM
Please can someone more knowledgeable than me let me know what I'm missing? Thanks. :)