The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-15-2006
steweston steweston is offline
Registered User
  
 

Join Date: May 2006
Location: Vancouver, BC
Posts: 11
Try a bit of awk

burakkilic,

I normally use awk for this kind of problem - it works effectively

awk '{tot+=$1} END{print tot}' numbers.txt

Alternatively, change your script as shown:

#!/bin/sh
sum=0
for i in `cat numbers.txt |cut -f1`
do
sum=`expr $sum + $i` # Add back quotes around the expr
done
echo $sum


Steve