Resurrecting an old thread (Was: printing words without newlines?)

Liste des GroupesRevenir à cl awk 
Sujet : Resurrecting an old thread (Was: printing words without newlines?)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : alt.comp.lang.awk comp.lang.awk
Date : 15. Jul 2024, 19:10:56
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <v73ong$3gdp5$1@news.xmission.com>
References : 1 2 3
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <v1t9hi$u4lh$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
...
Improved version:
>
{ A[$1] = $2 }
END {
   for (i=1; i<=NR; i++)
printf("%s%s",A[i],i<NR ? " " : "\n")
   }
>
Note that the value of NR in END is sort of a gray area, but it works as
expected in GAWK, which is really all we care about.

Here's an even tighter version.  Saves about 20 bytes of code.
Yes, I know this code makes a lot of assumptions, but all the assumptions
are valid in the instant case (and that's all that matters):

{ A[$1] = $2 }
END {
    for (i=1; i<=NR; i++) $i = A[i]
    print
    }

--
Joni Ernst (2014): Obama should be impeached because 2 people have died of Ebola.
Joni Ernst (2020): Trump is doing great things, because only 65,000 times as many people have died of COVID-19.

Josef Stalin (1947): When one person dies, it is a tragedy; when a million die, it is merely statistics.

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