home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 15906 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  1.1 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!haven.umd.edu!news.umbc.edu!math9.math.umbc.edu!rouben
  2. From: rouben@math9.math.umbc.edu (Rouben Rostamian)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: How to add a list of numbers?
  5. Date: 24 Jan 1993 22:09:23 GMT
  6. Organization: University of Maryland Baltimore Campus
  7. Lines: 15
  8. Message-ID: <1jv42jINNght@news.umbc.edu>
  9. References: <1993Jan24.120619.5072@mark-one.inet-uk.co.uk>
  10. NNTP-Posting-Host: math9.math.umbc.edu
  11.  
  12. In article <1993Jan24.120619.5072@mark-one.inet-uk.co.uk> mark@mark-one.inet-uk.co.uk (Mark Powell) writes:
  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. >All I can see is to write a for loop to add each number in turn to a
  18. >total, using expr.
  19.  
  20. ls -l | awk '{sum += $4} END{print "total: " sum}'
  21.  
  22. $4 refers to the fourth column in the input stream.  Replace it with
  23. any other column number as needed.
  24.  
  25. --
  26. Rouben Rostamian
  27.