[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
linux gawk 2.15pl6 broken ? (fwd)
Peter writes:
>
> Ok, the following message was not a casual announcement. TIA means Thank
> You In Advance. Can you please type the exmaple given below into your
> command lines and tell me ? Please ? TIA.
>
> ---------- Forwarded message ----------
> Date: Tue, 7 Oct 1997 14:19:26 +0000 (GMT)
> From: Peter <plp@actcom.co.il>
> To: linux-il@linux.org.il
> Subject: linux gawk 2.15pl6 broken ?
>
>
> Hi,
>
> when I do 'echo "a b c" | gawk 'BEGIN { OFS="\t"; } /^/ { print; }'
>
> I get "a b c" and no TABs. What am I (is gawk) doing wrong. What is the
> latest version / patch level.
>
I use gawk-3.0.0-5. I don't know if it is the latest or the greatest.
$0 is not recomputed unless you tell gawk (awk) to do it, and
therefore OFS is not used in output. Thus (note that you don't need
the caret in your example)
{~}$ echo "a b c" | gawk 'BEGIN { OFS=";"} //'
a b c
{~}$ echo "a b c" | gawk 'BEGIN { OFS=";"} {print $0}'
a b c
{~}$ echo "a b c" | gawk 'BEGIN { OFS=";"} {print}'
a b c
do not change OFS. Two ways to get OFS to work are
{~}$ echo "a b c" | gawk 'BEGIN { OFS=";"} {print $1, $2, $3}'
a;b;c
(accessing the fields explicitly) and
{~}$ echo "a b c" | gawk 'BEGIN { OFS=";"} {$1 = $1; print}'
a;b;c
("changing" the first field, thus $0, so OFS works).
So gawk is not broken.
Oleg.
goldshmt@netvision.net.il