🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.awk
Article #1

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

#1
From: Kenny McCormack
Date: Mon, 15 Jul 2024 18:10
29 lines
1778 bytes
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.
Technical Details
Message-ID: <v73ong$3gdp5$1@news.xmission.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!not-for-mail
References: <v1pi7c$2b87j$1@dont-email.me> <v1sdji$tofu$2@news.xmission.com> <v1t9hi$u4lh$1@news.xmission.com>

Show Full Headers
Complete Article Headers
Message-ID: <v73ong$3gdp5$1@news.xmission.com>
Subject: Resurrecting an old thread (Was: printing words without newlines?)
Date: Mon, 15 Jul 2024 18:10:56 +0000
From: gazelle@shell.xmission.com (Kenny McCormack)
References: <v1pi7c$2b87j$1@dont-email.me> <v1sdji$tofu$2@news.xmission.com> <v1t9hi$u4lh$1@news.xmission.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!not-for-mail
Newsgroups: alt.comp.lang.awk,comp.lang.awk
Organization: The official candy of the new Millennium
Injection-Date: Mon, 15 Jul 2024 18:10:56 -0000 (UTC)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)