Re: printing words without newlines?

Liste des GroupesRevenir à cl awk 
Sujet : Re: printing words without newlines?
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : alt.comp.lang.awk comp.lang.awk
Date : 13. May 2024, 18:26:56
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <v1tih0$u8kt$1@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <20240513100418.652@kylheku.com>,
Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
...
(This version more complicated than it needs to be, but essentially the
same as what I posted earlier)
$ awk '{
 if ($1 > max) max = $1;
 rank[$1] = $2
}
>
END {
 for (i = 1; i <= max; i++)
   if (i in rank) {
     printf("%s%s", sep, rank[i]);
     sep = " "
   }
 print ""
}' data.txt
all your base are belong to us
>
We do not perform any sort, and so we don't require GNU extensions. Sorting is

But GNU extensions are good - especially since OP specifically mentioned
using GAWK.  And much more on-topic than Lisp (et al).

Final note: In fact, it has been established (on this newsgroup as well as
empirically by me and others) that if the indices are small integers, you
get sorting for free (in GAWK, which, as noted, is all we care about).  So,
you don't even really need to mess with PROCINFO[]...

And, one more note about sorting.  Some responders on this thread have
gotten confused about what is to be sorted.  They assumed that OP wanted
the words sorted (alphabetically), when, in fact, he just wants them sorted
(numerically) by the position number (the first field in the data line).

--
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Mandela

Date Sujet#  Auteur
12 May 24 * printing words without newlines?19David Chmelik
12 May 24 +* Re: printing words without newlines?5Bruce Horrocks
12 May 24 i+- Re: printing words without newlines?1Bruce Horrocks
12 May 24 i`* Re: printing words without newlines?3Kenny McCormack
13 May 24 i +- Re: printing words without newlines?1David Chmelik
13 May 24 i `- Re: printing words without newlines?1Kaz Kylheku
13 May 24 +* Re: printing words without newlines?3Kenny McCormack
13 May 24 i`* Re: printing words without newlines?2Kenny McCormack
15 Jul 24 i `- Resurrecting an old thread (Was: printing words without newlines?)1Kenny McCormack
13 May 24 +- Re: printing words without newlines?1Janis Papanagnou
13 May 24 +* Re: printing words without newlines?4Kaz Kylheku
13 May 24 i`* Re: printing words without newlines?3Kenny McCormack
14 May 24 i `* Re: printing words without newlines?2Kaz Kylheku
14 May 24 i  `- Array indices are small integers? (Was: printing words without newlines?)1Kenny McCormack
16 May 24 `* Re: printing words without newlines?5Ed Morton
16 May 24  `* Re: printing words without newlines?4Janis Papanagnou
16 May 24   +* Once upon a time... (Was: printing words without newlines?)2Kenny McCormack
16 May 24   i`- Re: Once upon a time... (Was: printing words without newlines?)1Kenny McCormack
17 May 24   `- Re: printing words without newlines?1Ed Morton

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal