bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $x bug


From: Christoph Moser
Subject: Re: $x bug
Date: Fri, 05 Sep 2003 08:32:04 +0200 (MET DST)

Hi Aharon.

>>   > echo "5,4;4,6;6,7" | gawk -F ";" '{gsub(/[\,]/,"'",$1);print
>>   > $0}'
>>   5'4 4,6 6,7
>>
>> I think this is a bug. The result should be
>>
>>   5'4;4,6;6,7
> 
> No, it's not a bug.  Once $1 has changed, the original record is
> no longer valid.  Thus, when you want to print $0, gawk reconstitutes
> it by concatenting the fiels, separated by OFS.

Oh.I haven't found this in the AWK REFERENCE. The orginal problem code
was

  > echo "5,4;4,6;6,7" | gawk -F ";" \
  '{gsub(/\,/,"_",$1);gsub(/\,/,".");PARA_NAME=$1;print PARA_NAME}'
  5_4 4.6 6.7

But why give

  > echo "5,4;4,6;6,7" | gawk -F ";" \
  '{gsub(/\,/,"_",$1);PARA_NAME=$1;print PARA_NAME}'
  5_4

the "right" (wrong?) result?

So my failer analaysis was not so good. The explain of OFS (*output*
*field* separator, a space by default) don't show me, the field
separator where change *before* an output.

> If you set
>
>         OFS = ";"
>
> in the BEGIN block or with -v, you should get what you want.

Thank you, it works.

 > echo "5,4;4,6;6,7" | gawk -F ";" \
 'BEGIN{OFS=";"}{gsub(/\,/,"_",$1);gsub(/,/,".");PARA_NAME=$1;print \
 PARA_NAME}'
 5_4


Regards

  Christoph




reply via email to

[Prev in Thread] Current Thread [Next in Thread]