home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 16021 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.1 KB  |  29 lines

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