Message from discussion
Sum a numbers of a row
Received: by 10.66.81.98 with SMTP id z2mr3145151pax.19.1350319883123;
Mon, 15 Oct 2012 09:51:23 -0700 (PDT)
Path: s9ni9955pbb.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!webuse.net!not-for-mail
From: "Ed Morton" <mortons...@gmail.com>
Newsgroups: comp.lang.awk
Subject: Re: Sum a numbers of a row
Message-ID: <201210151651222493@webuse.net>
References: <c6d9dd0f-dbcd-4695-9634-a682244c70d6@k6g2000vbr.googlegroups.com>
Date: Mon, 15 Oct 2012 16:51:22 GMT
X-Newsreader: www.webuse.net
X-Complaints-To: abuse@webuse.net
NNTP-Posting-Host: 135.245.10.4
MIME-Version: 1.0
Bytes: 1585
Lines: 35
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
Roberto Zuelli <roberto...@gmail.com> wrote:
> Hello,
> I've a txt.file like this:
> A 1 2 3 0 0 6
> B 0 0 0 0 0 0
> J 0 0 0 1 0 9
> D 0 0 0 0 0 0
> O 0 99 0 1 0 9
> Q 13 0 0 1 0 9
> Z 0 0 5 8 0 8
>
> The dimension of the table (rows and columns) aren't known, the goal
> is make the sum of the elements for every row and print out the name
> of the firtst row (i.e A,B,J...) with sum =0 (In this case B).
> In the table there are more than different rows with all elemets =0
> but my objective is to identify the first one.
awk '{sum=0; for (i=2;i<=NF;i++) sum+=$i} !sum{print $1; exit}' file
> I use awk in another language (GAMS) so the commands used are into
> $onecho and $offecho.
No idea what that means.
Ed.
> Any idea?
>
> Thanks
>
> Roberto
>
Posted using www.webuse.net