From owner-freebsd-questions Mon May 22 3:42: 1 2000 Delivered-To: freebsd-questions@freebsd.org Received: from isy.liu.se (isy.liu.se [130.236.48.10]) by hub.freebsd.org (Postfix) with ESMTP id 637A237B507 for ; Mon, 22 May 2000 03:41:57 -0700 (PDT) (envelope-from mj@isy.liu.se) Received: from lagrange.isy.liu.se (lagrange.isy.liu.se [130.236.49.127]) by isy.liu.se (8.10.0/8.10.0) with ESMTP id e4MAfqx21435; Mon, 22 May 2000 12:41:52 +0200 (MET DST) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Mon, 22 May 2000 12:41:46 +0200 (CEST) From: Micke Josefsson To: Dan Larsson Subject: RE: calculate sum in sh Cc: questions@FreeBSD.ORG Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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