On 2/11/2008 8:26 AM, Ed Morton wrote:
>
> On 2/11/2008 3:40 AM, di98mase wrote:
>
>>Hi,
>>
>>when I run a gawk program from a console window I get a different
>>precision in my results from when I run the same program from a bat
>>file, why is that?
>>
>>This is how I run my program in the console window:
>>H:\semadu2\llt_tests\bl27\1.1.33.1\scripts>gawk -f..\..\..\..\scripts
>>\llt\llt_ca
>>lulate_transsaction_times.awk < ..\logs\test2.alc
>>
>>This gives the following output:
>>Tr Id USN Diff
>>----------------------------------------
>>00027037 0817F7DD 262.614
>>
>>If I run the same program from a batch file (extract below)
>>echo "******* Calculate all transaction times ***************"
>>..\..\..\..\tools\gawk -f ..\..\..\..\scripts\llt
>>\llt_calculate_transaction_times.awk <..\logs\%1 > ..\results
>>\transaction_times.res
>>
>>This gives the following output:
>>Tr Id USN Diff
>>----------------------------------------
>>00027037 0817F7DD 262
>>
>>As you can se the I loose the decimal precision? Why Is that?
>>(note that the outputs above are extracts)
>>
>
>
> It's almost certainly related to your locale setting. Personally, I've
never had
> much luck changing locales. The GNU awk manual
> (http://www.gnu.org/manual/gawk/html_node/Conversion.html)
says this
should work:
>
> $ echo 4,321 | gawk '{ print $1 + 1 }'
> -| 5
> $ echo 4,321 | LC_ALL=en_DK gawk '{ print $1 + 1 }'
> -| 5,321
>
> but here's what I get (gawk 3.1.6 on cygwin):
>
> $ echo 4,321 | gawk '{ print $1 + 1 }'
> 5
> $ echo 4,321 | LC_ALL=en_DK gawk '{ print $1 + 1 }'
> 5
>
> I've never pursued it as I never need it...
>
> Regards,
>
> Ed.
>
Well, I figured out my problem - cygwin gets its locale implementation
from
newlib which only sup****ts C locale
(http://sourceware.org/newlib/libc.html#SEC183).
For the OP, your problem may be similair, in which case converting the
","s to
"."s (possibly on-the-fly) should solve your problem:
$ echo 4,321 | gawk '{gsub(/,/,"."); $0 = $1 + 1; gsub(/\./,",")}1'
5,321
Regards,
Ed.


|