help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

summation in dc


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)

[I tried to send this msg to comp.gnu.utils this morning, but it never showed up. I'm trying this group now, through a different newsserver--apologies if this results in duplicates.]

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]