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

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

gawk always prints 0 for a hexadecimal number printed using printf %d


From: Mahendra Ladhe
Subject: gawk always prints 0 for a hexadecimal number printed using printf %d
Date: Thu, 6 Nov 2008 01:50:23 -0800

Hi,

   when a field on a line which is a hexadecimal number(preceded by 0x)
is printed

using printf with %d format specifier, gawk always prints 0 instead of
the value of the

field in the decimal format.

 

  Kindly see below the interactions at two different Linux machines.

 

On Fedora-7 Linux:

==============

address@hidden:~] gawk --version

GNU Awk 3.1.6

Copyright (C) 1989, 1991-2007 Free Software Foundation.

[snip]

 

address@hidden:~] cat /proc/version

Linux version 2.6.21-1.3194.fc7
(address@hidden) (gcc version 4.1.2
20070502 (Red Hat 4.1.2-12)) #1 SMP Wed May 23 22:35:01 EDT 2007

address@hidden:~] cat file.txt

0xf

address@hidden:~] gawk '{printf("%d\n", $1)}' file.txt

0

address@hidden:~] gawk '{printf("%d\n", 0xf)}' file.txt

15

 

As seen above, if some field is specified($1, $2 etc), it prints 0
always, but if a hard coded value like 0xf is

used, the correct value is printed in decimal.

 

 

On Ubuntu Linux:

============

>From 'man awk' command

 

AUTHOR

       Mike Brennan (address@hidden).

 

Version 1.2                       Dec 22 1994
MAWK(1)

 

address@hidden:~] cat /proc/version

Linux version 2.6.24-19-generic (address@hidden) (gcc version 4.2.3
(Ubuntu 4.2.3-2ubuntu7)) #1 SMP Wed Aug 20 22:56:21 UTC 2008

 

address@hidden:~] cat file.txt

0xf

address@hidden:~] awk '{printf("%d\n", $1)}' file.txt

15

 

 

So on a Ubuntu Linux with a very old version of (m)wk it's working
correctly.

 

 

Thanks,

Mahendra Ladhe

 

 



reply via email to

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