0

I'm trying to convert the hexadecimal value to a decimal value in my map file. For example, here is a snippet of the file

.bss       0xc     g2.comms
.bss       0xc     g2.comms
.bss       0xa     g2.comms
.bss       0x14    g2.comms
.rodata    0x64    g2.comms
.rodata    0x1ac   g2.comms
.rodata    0x270   g2.comms
.rodata    0x18    g2.comms

Is there a one line command that can convert the 2nd column from hexadecimal to decimal?

swapnil
  • 45
  • 5

1 Answers1

1

If you have GNU awk (gawk):

$ awk -n '{print $2+0}' file
12
12
10
20
100
428
624
24

-n (or --non-decimal-data) causes "the automatic interpretation of octal and hexadecimal values in input data." In order to make sure that awk treats the second column as a number, not a string, we add zero to it: $2+0.

John1024
  • 109,961
  • 14
  • 137
  • 171