[Gllug] Sum trouble

Doug Winter doug at pigeonhold.com
Tue Apr 8 10:39:53 UTC 2003


On Tue 08 Apr Leigh Mason wrote:
> Good morning all
> 
> I am trying to calculate the total sum of bytes listed in the apache 
> access_log.
> I have retrieved the particular column which gives me a list of byte 
> values thus:
> cut -f10 -d" " access_log
> 
> I can't seem to find any text type utility that will sum these values.
> What would be the usual procedure to achieve this?

I quite like:

  | awk 'BEGIN { print "0";} END {print "p";} {print $1 "\n+";}' |
    dc

The awk generates a stream of stack-based arithmetic to sum the incoming
stream of numbers, and dc does the actual adding up.  The zero at the
beginning ensures there are always two numbers on the stack.

doug.

-- 
Why should we be in such desperate haste to succeed, and in such desperate
enterprises?  If a man does not keep pace with his companions, perhaps it is
because he hears a different drummer.  Let him step to the music which he
hears, however measured or far away -- Henry David Thoreau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20030408/676f7de6/attachment.pgp>


More information about the GLLUG mailing list