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