The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 08-28-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
How about this?

Code:
#!/usr/bin/ksh
final=""
while read line; do
        case $line in
                [0-9]*.*[0-9]*-) final=$final-${line%-*};;
                *) final=$final+$line ;;
        esac
done < /path_to_file_with_numbers
finalsum=$(echo $final | bc)
echo $finalsum

I am not doing much error checking or validation here. The script expects valid numbers.