Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Sum a numbers of a row
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 28 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Roberto Zuelli  
View profile  
 More options Oct 15 2012, 11:30 am
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Mon, 15 Oct 2012 08:30:31 -0700 (PDT)
Local: Mon, Oct 15 2012 11:30 am
Subject: Sum a numbers of a row
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.
I use awk in another language (GAMS) so the commands used are into
$onecho and $offecho.

Any idea?

Thanks

Roberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed Morton  
View profile  
 More options Oct 15 2012, 12:51 pm
Newsgroups: comp.lang.awk
From: "Ed Morton" <mortons...@gmail.com>
Date: Mon, 15 Oct 2012 16:51:22 GMT
Local: Mon, Oct 15 2012 12:51 pm
Subject: Re: Sum a numbers of a row

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 15 2012, 12:57 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Mon, 15 Oct 2012 09:57:05 -0700 (PDT)
Local: Mon, Oct 15 2012 12:57 pm
Subject: Re: Sum a numbers of a row
On Oct 15, 5:51 pm, "Ed Morton" <mortons...@gmail.com> wrote:

$onecho and $offecho mean that I use awk as support language (I call
awk into GAMS to read files).

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 15 2012, 1:41 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Mon, 15 Oct 2012 10:41:09 -0700 (PDT)
Local: Mon, Oct 15 2012 1:41 pm
Subject: Re: Sum a numbers of a row
On Oct 15, 5:51 pm, "Ed Morton" <mortons...@gmail.com> wrote:

Considered that I have not too much confidence with awk, could you
explain what means: sum+=$i} !sum{print $1; exit}

Thanks a lot

R.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luuk  
View profile  
 More options Oct 15 2012, 2:20 pm
Newsgroups: comp.lang.awk
From: Luuk <l...@invalid.lan>
Date: Mon, 15 Oct 2012 20:18:32 +0200
Local: Mon, Oct 15 2012 2:18 pm
Subject: Re: Sum a numbers of a row
On 15-10-2012 19:41, Roberto Zuelli wrote:

  sum+=$i
is short for
sum=sum+$i

!sum{...}
when sum is 'false', the body is executed...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luuk  
View profile  
 More options Oct 15 2012, 2:30 pm
Newsgroups: comp.lang.awk
From: Luuk <l...@invalid.lan>
Date: Mon, 15 Oct 2012 20:23:21 +0200
Local: Mon, Oct 15 2012 2:23 pm
Subject: Re: Sum a numbers of a row
On 15-10-2012 17:30, Roberto Zuelli wrote:

> I use awk in another language (GAMS)

http://www.gams.com ?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 8:53 am
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 05:53:50 -0700 (PDT)
Local: Tues, Oct 16 2012 8:53 am
Subject: Re: Sum a numbers of a row
On Oct 15, 7:30 pm, Luuk <l...@invalid.lan> wrote:

> On 15-10-2012 17:30, Roberto Zuelli wrote:

> > I use awk in another language (GAMS)

> http://www.gams.com?

Yes Luuk, I use that GAMS...

Thanks everybody for everything.

Roberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 10:07 am
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 07:07:33 -0700 (PDT)
Local: Tues, Oct 16 2012 10:07 am
Subject: Re: Sum a numbers of a row
On Oct 16, 1:53 pm, Roberto Zuelli <roberto...@gmail.com> wrote:

> On Oct 15, 7:30 pm, Luuk <l...@invalid.lan> wrote:

> > On 15-10-2012 17:30, Roberto Zuelli wrote:

> > > I use awk in another language (GAMS)

> >http://www.gams.com?

> Yes Luuk, I use that GAMS...

> Thanks everybody for everything.

> Roberto

Sorry, but I have another problem...
I have a file like this:
Links  From   To      r
AA1    BUS1   BUS2    1
AA2    BUS3   BUS4    2
AA3    BUS2   BUS4    8
AA4    BUS1   BUS3    2
AA5    BUS3   BUS2    1

I'd like to print all the buses that appear in the 2 columns (from and
to) but just one time per each bus:
BUS1
BUS2
BUS3
BUS4
BUS5

Thanks

Roberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 11:16 am
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 17:16:51 +0200
Local: Tues, Oct 16 2012 11:16 am
Subject: Re: Sum a numbers of a row
On 16.10.2012 16:07, Roberto Zuelli wrote:

I don't see where you've got that BUS5 from.

Here's an awk command to play with...

   awk 'NR>1{a[$2];a[$3]}END{for(b in a)print b}'

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 12:10 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 09:10:15 -0700 (PDT)
Local: Tues, Oct 16 2012 12:10 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 4:16 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

Links  From   To      r
AA1    BUS1   BUS2    1
AA2    BUS3   BUS4    2
AA3    BUS2   BUS4    8
AA4    BUS1   BUS3    2
AA5    BUS5   BUS6    1
AA6    BUS7   BUS5    2
AA7    BUS2   BUS6    1

I mean, it will not print, for example, BUS6, isn't it? (If it is so,
how could I print also the buses that compare in just one column?)
Sorry for the basical question but I'm new with this language...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 12:20 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 18:20:11 +0200
Local: Tues, Oct 16 2012 12:20 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 18:10, Roberto Zuelli wrote:

Certainly it does, and it will also print BUS7, as it is in your newly
presented data. - Have you tried my script at all?

> (If it is so,
> how could I print also the buses that compare in just one column?)

Sorry, I don't understand what you are trying to say here. If you have
problems describing it with words, please provide sample data to make
your intention clear. And if I say sample data, I mean sample data that
will be appropriate to show what you want.

> Sorry for the basical question but I'm new with this language...

You're welcome also with basic questions; if you provide sufficient and
appropriate information so that we are able to help you.

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 12:46 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 09:46:00 -0700 (PDT)
Subject: Re: Sum a numbers of a row
On Oct 16, 5:20 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

Yes I've tried the command you suggested me but it works in a
particular way: it prints more than 1 time the same bus...

> Sorry, I don't understand what you are trying to say here. If you have
> problems describing it with words, please provide sample data to make
> your intention clear. And if I say sample data, I mean sample data that
> will be appropriate to show what you want.

I've a list of buses in two different columns, my goal is to print 1
time all the possible buses present in the 2 columns
NB certain buses compare just in the first column, certain other in
the second column and certain other in both the columns).

R.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 12:54 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 18:54:35 +0200
Local: Tues, Oct 16 2012 12:54 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 18:46, Roberto Zuelli wrote:

No, it does not do that. You must have made some mistake transcribing
the script (or have done some other mistake).

Show exactly the program that you used, show exactly how you called it,
and show exactly the results.

Here for comparison and for your convenience my call...

Input:
awk 'NR>1{a[$2];a[$3]}END{for(b in a)print b}' <<EOT
Links  From   To      r
AA1    BUS1   BUS2    1
AA2    BUS3   BUS4    2
AA3    BUS2   BUS4    8
AA4    BUS1   BUS3    2
AA5    BUS5   BUS6    1
AA6    BUS7   BUS5    2
AA7    BUS2   BUS6    1
EOT

Output:
BUS5
BUS6
BUS7
BUS1
BUS2
BUS3
BUS4

>> Sorry, I don't understand what you are trying to say here. If you have
>> problems describing it with words, please provide sample data to make
>> your intention clear. And if I say sample data, I mean sample data that
>> will be appropriate to show what you want.

> I've a list of buses in two different columns, my goal is to print 1
> time all the possible buses present in the 2 columns
> NB certain buses compare just in the first column, certain other in
> the second column and certain other in both the columns).

Yes, that's what your first requirement was, and that's what my script
does.

It's still not clear what your second requirement of your previous post
was.

Once again: Please provide appropriate sample data; input and requested
output data corresponding to your presented input data.

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 1:10 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 10:10:37 -0700 (PDT)
Local: Tues, Oct 16 2012 1:10 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 5:54 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

The data are the originals.

> It's still not clear what your second requirement of your previous post
> was.

You gave me the answer in the post before (I print all the possible
buses present in the 2 columns).

> Show exactly the program that you used, show exactly how you called it,
> and show exactly the results.

NR>1 {a[$2];a[$3]} end; for(b in a)print b

I put ";" after end because otherwise I get an error (I use awk as
support language in GAMS).

Results:
BUS1
BUS2
BUS3
BUS1
BUS4
BUS2
BUS3

R.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 1:26 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 19:26:37 +0200
Local: Tues, Oct 16 2012 1:26 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 19:10, Roberto Zuelli wrote:

> On Oct 16, 5:54 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
>> awk 'NR>1{a[$2];a[$3]}END{for(b in a)print b}'
[...]
>> Show exactly the program that you used, show exactly how you called it,
>> and show exactly the results.

> NR>1 {a[$2];a[$3]} end; for(b in a)print b

> I put ";" after end because otherwise I get an error (I use awk as
> support language in GAMS).

I said
        NR>1{a[$2];a[$3]}END{for(b in a)print b}
and not
        NR>1 {a[$2];a[$3]} end; for(b in a)print b

The latter is not even a valid awk program.

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luuk  
View profile  
 More options Oct 16 2012, 1:30 pm
Newsgroups: comp.lang.awk
From: Luuk <l...@invalid.lan>
Date: Tue, 16 Oct 2012 19:28:16 +0200
Local: Tues, Oct 16 2012 1:28 pm
Subject: Re: Sum a numbers of a row
On 16-10-2012 19:10, Roberto Zuelli wrote:

> On Oct 16, 5:54 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
> wrote:
>> On 16.10.2012 18:46, Roberto Zuelli wrote:

> NR>1 {a[$2];a[$3]} end; for(b in a)print b

> I put ";" after end because otherwise I get an error (I use awk as
> support language in GAMS).

and, finally.....

'end' should be i capitals...
like 'END'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luuk  
View profile  
 More options Oct 16 2012, 1:30 pm
Newsgroups: comp.lang.awk
From: Luuk <l...@invalid.lan>
Date: Tue, 16 Oct 2012 19:25:31 +0200
Local: Tues, Oct 16 2012 1:25 pm
Subject: Re: Sum a numbers of a row
On 16-10-2012 19:10, Roberto Zuelli wrote:

> On Oct 16, 5:54 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
> wrote:

> NR>1 {a[$2];a[$3]} end; for(b in a)print b

> I put ";" after end because otherwise I get an error (I use awk as
> support language in GAMS).

You should not do that....

Can you tell us waht the output is of:
awk -V

it should print something like:
GNU Awk 4.0.0
Copyright (C) 1989, 1991-2011 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

But possibly you have an older version, or.... (somthing else)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 1:36 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 10:36:46 -0700 (PDT)
Local: Tues, Oct 16 2012 1:36 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 6:26 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

If I don't use the ";" I get error while if I use it I get the output
previously specified.

R.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 1:37 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 19:37:21 +0200
Local: Tues, Oct 16 2012 1:37 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 19:28, Luuk wrote:

Luuk, that is not the only problem the OP has with his clueless modification.
He also shouldn't terminate the condition by a semicolon, otherwise he'd get
the default action {print $0} if the condition is true; but OTOH, as in his
malformed modification, any undefined variable (like 'end') will be be false
anyway). And he has written the for-loop, which is valid only as action in
an action-part within {...}, stand-alone as condition. There's so many wrong
with that posters code (and posting habits).

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 1:42 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 19:42:27 +0200
Local: Tues, Oct 16 2012 1:42 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 19:36, Roberto Zuelli wrote:

I am going to lose my patience, Roberto. How can we help you, if
you don't give accurate information?! - What "error" do you get?
From what awk version? - Or is it that "GAMS" that has issues?
(But then you should post in a GAMS newsgroup.) I fear that what
you are using might not be a real awk, since it seems to accept
your code which is obviously malformed syntax.

Janis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 1:48 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 10:48:04 -0700 (PDT)
Local: Tues, Oct 16 2012 1:48 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 6:37 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

I'm using awk as support language and that means that it's recalled by
the principal program (GAMS, for which my company BOUGHT an official
licence!) and for this I do NOT need about all that stuff about which
Luuk speaks!

Janis:
I understand that the semicolon is wrong but if I do not use it I get
the error.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 1:50 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 19:50:16 +0200
Local: Tues, Oct 16 2012 1:50 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 19:48, Roberto Zuelli wrote:

> Janis:
> I understand that the semicolon is wrong but if I do not use it I get
> the error.

*WHAT* error, please!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 1:51 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 10:51:05 -0700 (PDT)
Local: Tues, Oct 16 2012 1:51 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 6:50 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

> On 16.10.2012 19:48, Roberto Zuelli wrote:

> > Janis:
> > I understand that the semicolon is wrong but if I do not use it I get
> > the error.

> *WHAT* error, please!

> - Hide quoted text -

> - Show quoted text -

parse error

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Janis Papanagnou  
View profile  
 More options Oct 16 2012, 1:57 pm
Newsgroups: comp.lang.awk
From: Janis Papanagnou <janis_papanag...@hotmail.com>
Date: Tue, 16 Oct 2012 19:57:56 +0200
Local: Tues, Oct 16 2012 1:57 pm
Subject: Re: Sum a numbers of a row
On 16.10.2012 19:51, Roberto Zuelli wrote:

*sigh* - I give up.

Having asked so many times to provide accurate information from which
we can deduce anything, and always just got trash... - good luck with
all you attempt to do in life.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Zuelli  
View profile  
 More options Oct 16 2012, 2:01 pm
Newsgroups: comp.lang.awk
From: Roberto Zuelli <roberto...@gmail.com>
Date: Tue, 16 Oct 2012 11:01:28 -0700 (PDT)
Local: Tues, Oct 16 2012 2:01 pm
Subject: Re: Sum a numbers of a row
On Oct 16, 6:57 pm, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:

Sorry if you've lost your time but all what I wrote was what I had,
nothing more nothing less!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 28   Newer >
« Back to Discussions « Newer topic     Older topic »