Re: printing words without newlines?
[email protected] (Kenny McCormack) Mon, 13 May 2024 14:53:38 -0000 (UTC)
| Newsgroups | alt.comp.lang.awk,comp.lang.awk |
|---|---|
| Organization | The official candy of the new Millennium |
| Message-ID | <[email protected]> |
In article <[email protected]>, Kenny McCormack <[email protected]> wrote: ... >I guess this is what you actually want: > >{ A[$1] = $2 } >END { > len = length(A) > for (i=1; i<=len; i++) > printf("%s%s",A[i],i<len ? " " : "\n") > } 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. -- [Donald] Trump didn't have it all handed to him by his parents, like Hillary Clinton did. - Some dumb cluck in Ohio; featured in Michael Moore's "Trumpland" -