Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 May 2000 12:41:46 +0200 (CEST)
From:      Micke Josefsson <mj@isy.liu.se>
To:        Dan Larsson <dl@tyfon.net>
Cc:        questions@FreeBSD.ORG
Subject:   RE: calculate sum in sh
Message-ID:  <XFMail.000522124146.mj@isy.liu.se>
In-Reply-To: <NEBBJANJCNNAKCPFKHHFKEHBCEAA.dl@tyfon.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On 22-May-00 Dan Larsson wrote:
> How to I calculate the sum of all values, the
> values are listed one value per line in a textfile 
> using shell commands (no perl available)?
> 
Not pure shelling, but you can try this with awk

File 'crap.txt' is :

1
2
3
20

then 

lagrange> awk '{sum += $0} END{print "Grand total is "sum}' crap.txt
Grand total is 26

Use $1 if you want field number 1 instead of summing the entire line,
which is OK in this example.

/M

----------------------------------
Michael Josefsson, MSEE
mj@isy.liu.se

This message was sent by XFMail
running on FreeBSD 3.4
----------------------------------


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.000522124146.mj>