home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!math.fu-berlin.de!ira.uka.de!smurf.sub.org!easix!bc3!ktf
- From: ktf@bc3.gun.de (Klaus ter Fehn)
- Subject: Re: How to add a list of numbers?
- Organization: private
- Date: Wed, 27 Jan 1993 20:26:26 GMT
- Message-ID: <C1J4s3.C8x@bc3.gun.de>
- X-Newsreader: TIN [version 1.1 PL6]
- References: <1993Jan24.120619.5072@mark-one.inet-uk.co.uk>
- Lines: 17
-
- Mark Powell (mark@mark-one.inet-uk.co.uk) wrote:
- > What is the best (least CPU time) to addup a list of ASCII numbers?
- > eg you've just used cut to extract a list of file sizes from a ls -l
- > listing and now want to add all the numbers together. Is there some
- > utility that will do this?
-
- SUM=`ls -l | awk '
- NR > 1 { sum += $5 }
- END { print sum }'`
-
- - I split the lines because it is more readable.
- - The NR > 1 inside the awk-script is used to skip the 'total'-line.
- --
- LONDON ---* *--- BERLIN Klaus ter Fehn
- *--- <ktf@bc3.gun.de> Neanderstr. 4
- {mcshh,smurf,unido}!easix!bc3!ktf 4000 Duesseldorf 1
- PARIS ---* Tel.: +49-211-676331 FRG / Germany
-