LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 03-15-2005, 10:15 AM   #1
UnHolier
LQ Newbie
 
Registered: Mar 2005
Location: Montréal, Qc, Canada
Distribution: Mandrake 10
Posts: 2

Rep: Reputation: 0
Awk losing significant figures.


Hi,

I have problems with awk. Basically, as soon as I use some mathematical expression I lose all but 1 or 2 significant digits. The problem does not occur on a different machine (which runs Mandrake 9.x), and installing the latest version of awk did not help. It really seems to be due to my particular settings.

I am running awk 3.1.4 on Mandrake 10.1

Here is an example of the behaviour of awk. The input file is

+0.000000E+00 -2.517389E-10^M +0.000000E+00 +9.685495E-01
+1.000000E-03 +8.594784E-09^M +1.000000E-03 +9.689896E-01
+2.000000E-03 +1.751617E-08^M +2.000000E-03 +9.641005E-01
+3.000000E-03 +2.649998E-08^M +3.000000E-03 +9.645113E-01
+4.000000E-03 +3.565420E-08^M +4.000000E-03 +9.702466E-01

I now execute

awk '{print $1, $2, $4*1e-2}'

and the output is

+0.000000E+00 -2.517389E-10^M 0,09
+1.000000E-03 +8.594784E-09^M 0,09
+2.000000E-03 +1.751617E-08^M 0,09
+3.000000E-03 +2.649998E-08^M 0,09
+4.000000E-03 +3.565420E-08^M 0,09

As you can see, the first digit (9) is good, but the order of magnitude is wrong and all other digits have been lost. Different mathematical expressions yield similar results, for example

awk '{print $1, $2, $4+$4}'

will output

+0.000000E+00 -2.517389E-10^M 18
+1.000000E-03 +8.594784E-09^M 18
+2.000000E-03 +1.751617E-08^M 18
+3.000000E-03 +2.649998E-08^M 18
+4.000000E-03 +3.565420E-08^M 18

Again, we only keep 9+9=18, everything after the decimal place is gone.

A problem might be that my system is set-up in french, although it usually take the dot as the decimal place separator, the comma is the official one. However, I do not know how to change these settings in awk.

Thanks for your help.
 
Old 03-15-2005, 10:28 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
My guess is that awk would take settings from your current locale with respect to the ./, issue, which may well be your problem.
 
Old 03-15-2005, 10:47 AM   #3
bunnadik
Member
 
Registered: Jan 2005
Location: Övik, Sweden
Distribution: MDK 10.1
Posts: 450

Rep: Reputation: 30
I concur. With LC_ALL="sv_SE" I got the same erroneous output.
After setting 'export LC_ALL=en' I got :

+0.000000E+00 -2.517389E-10^M 0.0096855
+1.000000E-03 +8.594784E-09^M 0.0096899
+2.000000E-03 +1.751617E-08^M 0.00964101
+3.000000E-03 +2.649998E-08^M 0.00964511
+4.000000E-03 +3.565420E-08^M 0.00970247

- Peder
 
Old 03-15-2005, 11:07 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Fyi, you can always use "tr ',' '.'" in there to translate if you don't want to mess with locales. (This assumes, of course, that all commas are decimals, and that no other dots are in use.)
 
Old 03-15-2005, 12:54 PM   #5
UnHolier
LQ Newbie
 
Registered: Mar 2005
Location: Montréal, Qc, Canada
Distribution: Mandrake 10
Posts: 2

Original Poster
Rep: Reputation: 0
It works

awk itself uses commas, so using "tr ',' '.'" might cause other problems.

However, changing the locale to english works fine. Thanks a lot!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Predicts Significant Sales Decline due to Linux. rvijay General 2 09-03-2004 07:53 PM
MySQL :: Table in query adds significant delay lackluster Programming 7 07-10-2004 03:48 AM
CPU optimization at build, improvement significant? gundelgauk Programming 2 11-17-2003 03:27 PM
LaTeX problem with figures guygriffiths Linux - Software 4 11-15-2003 01:35 PM
how to edit ps figures? dragon Linux - Software 1 07-02-2003 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 11:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration