From: Darryl Ousterhout (D.Ousterhout@LABSAFETY.COM)
Date: Fri Oct 18 2002 - 15:51:19 EDT
You could probably use something like this, where col=x is whatever column
in the file that you want summed up:
cat <file> | awk '{sum += $col } END {print sum}' col=1
In a simple script:
SUM1=$(df -k | sed 1d | awk '{sum += $col } END {print sum}' col=2)
SUM2=$(df -k | sed 1d | awk '{sum += $col } END {print sum}' col=3)
echo $SUM1
echo $SUM2
expr $SUM1 - $SUM2
Regards,
Darryl
-----Original Message-----
From: Michelle DeVault [mailto:adsmigmo@YAHOO.COM]
Sent: Friday, October 18, 2002 2:32 PM
To: aix-l@Princeton.EDU
Subject: easy way to add a bunch of numbers in a script
I have a column of numbers (either in a variable or
written to a file) that I need to total in a script.
What's the preferred way to do this?
__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:16 EDT