Groups | Search | Server Info | Login | Register


Groups > alt.comp.lang.awk > #24

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

From gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups alt.comp.lang.awk, comp.lang.awk
Subject Resurrecting an old thread (Was: printing words without newlines?)
Date 2024-07-15 18:10 +0000
Organization The official candy of the new Millennium
Message-ID <v73ong$3gdp5$1@news.xmission.com> (permalink)
References <v1pi7c$2b87j$1@dont-email.me> <v1sdji$tofu$2@news.xmission.com> <v1t9hi$u4lh$1@news.xmission.com>

Cross-posted to 2 groups.

Show all headers | View raw


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.

Back to alt.comp.lang.awk | PreviousPrevious in thread | Next in thread | Find similar


Thread

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