|
From: | Mike Maxwell |
Subject: | summation in dc |
Date: | Wed, 11 Aug 2004 14:01:29 -0400 |
User-agent: | Mozilla Thunderbird 0.7.3 (Windows/20040803) |
A frequent task I have is to sum a series of numbers. The 'dc' utility is a nice tool, but I don't see any obvious way of using it to sum a list of arbitrary length. Well, I guess I could use wc -l to find out how many numbers I was going to sum, then keep decrementing that, but that seems clumsy...
I can read the numbers into dc, then keep hitting the "+" key until I get a "stack empty" error, then do "p". But that also seems clumsy, and besides, I want this to run automatically, without keystrokes, or me waiting to see the error msg.
Maybe there's a way of doing this with macros in dc? Or in bc? Or in some other tool? If the latter, it needs to be s.t. readily available, as I want it to work in several different environments (CygWin, Linux, FreeBSD).
Mike Maxwell
[Prev in Thread] | Current Thread | [Next in Thread] |