Groups | Search | Server Info | Login | Register
Groups > comp.lang.awk > #9739
| From | gazelle@shell.xmission.com (Kenny McCormack) |
|---|---|
| Newsgroups | alt.comp.lang.awk, comp.lang.awk |
| Subject | Re: printing words without newlines? |
| Date | 2024-05-13 17:26 +0000 |
| Organization | The official candy of the new Millennium |
| Message-ID | <v1tih0$u8kt$1@news.xmission.com> (permalink) |
| References | <v1pi7c$2b87j$1@dont-email.me> <20240513100418.652@kylheku.com> |
Cross-posted to 2 groups.
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
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
printing words without newlines? David Chmelik <dchmelik@gmail.com> - 2024-05-12 04:57 +0000
Re: printing words without newlines? Bruce Horrocks <07.013@scorecrow.com> - 2024-05-12 09:52 +0100
Re: printing words without newlines? Bruce Horrocks <07.013@scorecrow.com> - 2024-05-12 09:55 +0100
Re: printing words without newlines? gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-12 12:11 +0000
Re: printing words without newlines? David Chmelik <dchmelik@gmail.com> - 2024-05-13 02:04 +0000
Re: printing words without newlines? Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-13 16:49 +0000
Re: printing words without newlines? gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-13 06:56 +0000
Re: printing words without newlines? gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-13 14:53 +0000
Resurrecting an old thread (Was: printing words without newlines?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-07-15 18:10 +0000
Re: printing words without newlines? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-13 10:18 +0200
Re: printing words without newlines? Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-13 17:17 +0000
Re: printing words without newlines? gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-13 17:26 +0000
Re: printing words without newlines? Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-13 23:33 +0000
Array indices are small integers? (Was: printing words without newlines?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-14 13:40 +0000
Re: printing words without newlines? Ed Morton <mortonspam@gmail.com> - 2024-05-16 08:11 -0500
Re: printing words without newlines? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-16 15:55 +0200
Once upon a time... (Was: printing words without newlines?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-16 14:15 +0000
Re: Once upon a time... (Was: printing words without newlines?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-05-16 15:17 +0000
Re: printing words without newlines? Ed Morton <mortonspam@gmail.com> - 2024-05-16 19:40 -0500
csiph-web