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)
|
|
0
|
|
|
|
Reply
|
di98mase
|
2/11/2008 9:40:47 AM |
|
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.
|
|
0
|
|
|
|
Reply
|
Ed
|
2/11/2008 2:26:47 PM
|
|
> This is how I run my program in the console window:
> H:\semadu2\llt_tests\bl27\1.1.33.1\scripts>gawk -f..\..\..\..\scripts
[...]
> If I run the same program from a batch file (extract below)
> echo "******* Calculate all transaction times ***************"
> ..\..\..\..\tools\gawk -f ..\..\..\..\scripts\llt
While Ed's probably got it with the locale, it looks like you're
running 2 different gawks
|
|
0
|
|
|
|
Reply
|
Toby
|
2/11/2008 3:00:11 PM
|
|
On 11 Feb, 16:00, Toby Darling <anothercof...@googlemail.com> wrote:
> > This is how I run my program in the console window:
> > H:\semadu2\llt_tests\bl27\1.1.33.1\scripts>gawk -f..\..\..\..\scripts
> [...]
> > If I run the same program from a batch file (extract below)
> > echo "******* Calculate all transaction times ***************"
> > ..\..\..\..\tools\gawk -f ..\..\..\..\scripts\llt
>
> While Ed's probably got it with the locale, it looks like you're
> running 2 different gawks
Hi Toby,
I understand why you think so but I am not. The thing is that a have
set the PATH to find gawk. That is why I can use gawk from the scripts
folder in the first example. In the latter example I use a relative
path to the same folder as specified in the PATH.
I also tried the example found in the manual with the same result. I
did notice one thing though. I cant find the LC_ALL variable in a
console window it is only "valid" in cygwin? Also, one thing that
makes no sence is that use a console window in both cases above. I
dont use Cygwin or anything else. I would not suspect windows to
behave different in a console or a batch file...well no precision is
fine for me but it bothers me a bit when I dont know why it happens.
Thanks for your input...
|
|
0
|
|
|
|
Reply
|
di98mase
|
2/11/2008 4:08:08 PM
|
|
On Feb 11, 11:08 am, di98mase <di98m...@hotmail.com> wrote:
> On 11 Feb, 16:00, Toby Darling <anothercof...@googlemail.com> wrote:
>
> > > This is how I run my program in the console window:
> > > H:\semadu2\llt_tests\bl27\1.1.33.1\scripts>gawk -f..\..\..\..\scripts
> > [...]
> > > If I run the same program from a batch file (extract below)
> > > echo "******* Calculate all transaction times ***************"
> > > ..\..\..\..\tools\gawk -f ..\..\..\..\scripts\llt
>
> > While Ed's probably got it with the locale, it looks like you're
> > running 2 different gawks
>
> Hi Toby,
>
> I understand why you think so but I am not. The thing is that a have
> set the PATH to find gawk. That is why I can use gawk from the scripts
> folder in the first example. In the latter example I use a relative
> path to the same folder as specified in the PATH.
>
> I also tried the example found in the manual with the same result. I
> did notice one thing though. I cant find the LC_ALL variable in a
> console window it is only "valid" in cygwin? Also, one thing that
> makes no sence is that use a console window in both cases above. I
> dont use Cygwin or anything else. I would not suspect windows to
> behave different in a console or a batch file...well no precision is
> fine for me but it bothers me a bit when I dont know why it happens.
>
> Thanks for your input...
Just for grins you might want to try "gawk --version" both
interactively and from a .BAT file, and compare the results. That is,
if you haven't already done so. :-)
|
|
0
|
|
|
|
Reply
|
Galen
|
2/11/2008 5:29:25 PM
|
|
Hi
> I understand why you think so but I am not. The thing is that a have
No problem, just checking.
> I also tried the example found in the manual with the same result. I
> did notice one thing though. I cant find the LC_ALL variable in a
> console window it is only "valid" in cygwin? Also, one thing that
> makes no sence is that use a console window in both cases above. I
> dont use Cygwin or anything else. I would not suspect windows to
> behave different in a console or a batch file...well no precision is
> fine for me but it bothers me a bit when I dont know why it happens.
You'll need to 'set LC_ALL=en_DK' in the window or batch file, but
that doesn't seem to make any difference for me.
I'm no wiser as to what's going wrong either, I can only get the
correct [unrounded] output if I replace 4,321 with 4.321 (in Ed's
example).
|
|
0
|
|
|
|
Reply
|
Toby
|
2/11/2008 6:01:45 PM
|
|
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 supports 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.
|
|
0
|
|
|
|
Reply
|
Ed
|
2/11/2008 6:37:57 PM
|
|
On 11 Feb, 19:37, Ed Morton <mor...@lsupcaemnt.com> wrote:
> 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 =A0 =A0 USN =A0 =A0 =A0 =A0Diff
> >>----------------------------------------
> >>00027037 =A00817F7DD =A0 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 =A0 =A0 USN =A0 =A0 =A0 =A0Diff
> >>----------------------------------------
> >>00027037 =A00817F7DD =A0 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 n=
ever had
> > much luck changing locales. The GNU awk manual
> > (http://www.gnu.org/manual/gawk/html_node/Conversion.html) says this sho=
uld work:
>
> > =A0 =A0 =A0$ echo 4,321 | gawk '{ print $1 + 1 }'
> > =A0 =A0 =A0-| 5
> > =A0 =A0 =A0$ echo 4,321 | LC_ALL=3Den_DK gawk '{ print $1 + 1 }'
> > =A0 =A0 =A0-| 5,321
>
> > but here's what I get (gawk 3.1.6 on cygwin):
>
> > =A0 =A0 =A0$ echo 4,321 | gawk '{ print $1 + 1 }'
> > =A0 =A0 =A05
> > =A0 =A0 =A0$ echo 4,321 | LC_ALL=3Den_DK gawk '{ print $1 + 1 }'
> > =A0 =A0 =A05
>
> > I've never pursued it as I never need it...
>
> > Regards,
>
> > =A0 =A0Ed.
>
> Well, I figured out my problem - cygwin gets its locale implementation fro=
m
> newlib which only supports C locale (http://sourceware.org/newlib/libc.htm=
l#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 =3D $1 + 1; gsub(/\./,",")}1'
> 5,321
>
> Regards,
>
> =A0 =A0 =A0 =A0 Ed.- D=F6lj citerad text -
>
> - Visa citerad text -
Hi again,
I have searched the reference manual for more info about different
locale but without any luck? How shall I write if I want to set the
LC_ALL to swedish for instance? Also, are there more environment
variables that can be set or changed?
Rgds
/di98
|
|
0
|
|
|
|
Reply
|
di98mase
|
2/12/2008 12:43:40 PM
|
|
On 2/12/2008 6:43 AM, di98mase wrote:
> On 11 Feb, 19:37, Ed Morton <mor...@lsupcaemnt.com> wrote:
>=20
>>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 s=
hould work:
>>
>>> $ echo 4,321 | gawk '{ print $1 + 1 }'
>>> -| 5
>>> $ echo 4,321 | LC_ALL=3Den_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=3Den_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 supports 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 =3D $1 + 1; gsub(/\./,",")}1'
>>5,321
>>
>>Regards,
>>
>> Ed.- D=F6lj citerad text -
>>
>>- Visa citerad text -
>=20
>=20
> Hi again,
>=20
> I have searched the reference manual for more info about different
> locale but without any luck?
Which reference manual? Hopefully the one for your OS rather than the one=
for awk.
> How shall I write if I want to set the
> LC_ALL to swedish for instance?
If it's not in your OS documentation, you stand a better chance of gettin=
g the
right answer if you post that question to an OS-specific NG. For example,=
in
this case with GNU awk, as we discovered you'll get a different answer if=
you're
on cygwin or Solaris.
> Also, are there more environment
> variables that can be set or changed?
Yes and they should be in the documentation for the specific awk that you=
use,
but they'll probably be spread out in various sections based on the
functionality they affect. Sometimes it's undocumented, though, such as
"WHINY_USERS" (seriously!) for gawk.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
2/12/2008 1:32:07 PM
|
|
On 12 Feb, 14:32, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 2/12/2008 6:43 AM, di98mase wrote:
>
>
>
>
>
> > On 11 Feb, 19:37, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
> >>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 =A0 =A0 USN =A0 =A0 =A0 =A0Diff
> >>>>----------------------------------------
> >>>>00027037 =A00817F7DD =A0 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 =A0 =A0 USN =A0 =A0 =A0 =A0Diff
> >>>>----------------------------------------
> >>>>00027037 =A00817F7DD =A0 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 sh=
ould work:
>
> >>> =A0 =A0 $ echo 4,321 | gawk '{ print $1 + 1 }'
> >>> =A0 =A0 -| 5
> >>> =A0 =A0 $ echo 4,321 | LC_ALL=3Den_DK gawk '{ print $1 + 1 }'
> >>> =A0 =A0 -| 5,321
>
> >>>but here's what I get (gawk 3.1.6 on cygwin):
>
> >>> =A0 =A0 $ echo 4,321 | gawk '{ print $1 + 1 }'
> >>> =A0 =A0 5
> >>> =A0 =A0 $ echo 4,321 | LC_ALL=3Den_DK gawk '{ print $1 + 1 }'
> >>> =A0 =A0 5
>
> >>>I've never pursued it as I never need it...
>
> >>>Regards,
>
> >>> =A0 Ed.
>
> >>Well, I figured out my problem - cygwin gets its locale implementation f=
rom
> >>newlib which only supports C locale (http://sourceware.org/newlib/libc.h=
tml#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 =3D $1 + 1; gsub(/\./,",")}1'
> >>5,321
>
> >>Regards,
>
> >> =A0 =A0 =A0 =A0Ed.- D=F6lj citerad text -
>
> >>- Visa citerad text -
>
> > Hi again,
>
> > I have searched the reference manual for more info about different
> > locale but without any luck?
>
> Which reference manual? Hopefully the one for your OS rather than the one =
for awk.
>
> > How shall I write if I want to set the
> > LC_ALL to swedish for instance?
>
> If it's not in your OS documentation, you stand a better chance of getting=
the
> right answer if you post that question to an OS-specific NG. For example, =
in
> this case with GNU awk, as we discovered you'll get a different answer if =
you're
> on cygwin or Solaris.
>
> > Also, are there more environment
> > variables that can be set or changed?
>
> Yes and they should be in the documentation for the specific awk that you =
use,
> but they'll probably be spread out in various sections based on the
> functionality they affect. Sometimes it's undocumented, though, such as
> "WHINY_USERS" (seriously!) for gawk.
>
> =A0 =A0 =A0 =A0 Ed.- D=F6lj citerad text -
>
> - Visa citerad text -
Ok, thanks all for your help. It is much appreciated!
|
|
0
|
|
|
|
Reply
|
di98mase
|
2/12/2008 2:28:44 PM
|
|
|
9 Replies
136 Views
(page loaded in 0.224 seconds)
|