🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #15837

Re: Suma con expr

#15837
From: J.A. Gutierrez
Date: Fri, 02 Jun 2000 00:00
54 lines
1718 bytes
Esteban <scandisk@ctv.es> wrote:

: Tengo el fichero "a" con un mont�n de n�meros:

: 54515
: 14587
: 12569
: 877445
: 12555
: etc....

: �C�mo para sumarlos?

* awk

$ (echo 2; echo 3) | awk '{i+=$0}END{print i}'
5

* dc

$ (echo 2; echo 3) |\
(echo 0 ; while read line; do echo $line +; done; echo p )| dc
5

* posix sh

$ (echo 2; echo 3) |\ 
(let a=0; while read line; do let a=$a+$line; done; echo $a)
5

* sh + expr

$ (echo 2; echo 3) |\ 
(a=0; while read line; do a=`expr $a + $line`; done; echo $a)
5

* :-)

$ (echo 2; echo 3) |\
(
while read line
do
	dd if=/dev/zero bs=$line count=1 2>/dev/null
done
) | wc -c
5



-- 
PGP and other useless info at      \                 Oh, show us the way
http://www.cps.unizar.es/~spd/      \             to the next whisky bar
finger://daphne.cps.unizar.es/spd    \                      Weill/Bretch
es doloroso ser sabio y descubrir la sopa de ajo                   (Pla)
Technical Details
Message-ID: <8h8epg$sps$1@news.unizar.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <slrn8jdoiu.72r.scandisk@localhost.localdomain>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f86c8,27fa0f38991f2bdb
X-Google-Attributes: gidf86c8,public
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Subject: Re: Suma con expr
Date: 2000/06/02
Message-ID: <8h8epg$sps$1@news.unizar.es>
X-Deja-AN: 630225431
Content-Transfer-Encoding: 8bit
References: <slrn8jdoiu.72r.scandisk@localhost.localdomain>
Content-Type: text/plain; charset=ISO-8859-1
X-Complaints-To: usenet@news.unizar.es
X-Trace: news.unizar.es 959954544 29500 155.210.152.20 (2 Jun 2000 14:02:24 GMT)
Organization: Rank
Mime-Version: 1.0
User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (IRIX/6.2 (IP22))
NNTP-Posting-Date: 2 Jun 2000 14:02:24 GMT
Newsgroups: es.comp.os.linux.programacion