🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.lang.awk
1 messages
1 total messages Started by Kenny McCormack Mon, 15 Jul 2024 18:10
Resurrecting an old thread (Was: printing words without newlines?)
#1
Author: 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads