[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The correct way to print hex number as dec number?
From: |
Andrew J. Schorr |
Subject: |
Re: The correct way to print hex number as dec number? |
Date: |
Fri, 13 Mar 2020 14:36:03 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
On Fri, Mar 13, 2020 at 11:30:21AM -0500, Peng Yu wrote:
> I see that --non-decimal-data must be used to print hex number as a
> dec number. Is it the correct way to do so? I'd like to control this a
> finer scale. Is there a way to dictate which column this option is
> effective? Thanks.
>
> $ awk --non-decimal-data '{ printf("%d\n", $1) }' <<< '0xaaaa'
> 43690
> $ awk '{ printf("%d\n", $1) }' <<< '0xaaaa'
> 0
Yes. Use the strtonum function:
bash-4.2$ echo 0xaaaa | gawk '{print $1+0}'
0
bash-4.2$ echo 0xaaaa | gawk --non-decimal-data '{print $1+0}'
43690
bash-4.2$ echo 0xaaaa | gawk '{print strtonum($1)+0}'
43690
Regards,
Andy
Re: The correct way to print hex number as dec number?,
Andrew J. Schorr <=