I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there.
I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and append 0x to the front but the printf statement seems not to work to convert it to decimal. I dumped my output to a file and have been trying to get it to convert so I can proceed on.
Here are the last lines snipped from my file, as it it large:
0x0C0,###0,33,6291
0x011,###1,59,0
0x009,###0,59,362147
0x011,###2,59,260
0x00E,###2,59,1051
0x008,###1,33,0
0x034,###2,59,0
0x001,###3,59,208
0x00E,###2,33,52
0x034,###2,33,0
0x00F,###1,59,0
0x009,###0,33,33022
From the shell prompt I tried:
printf "%d\n" 0x03E
and get the proper output:
62
If I type:
cat <file>|nawk -F, '{printf "%d\n" , $1}'
I get nothing but zeroes as output:
0
0
0
0
0
0
0
0
0
I tested via:
cat <file>|nawk -F, '{$1," ""%d\n",$1}'
and my output has the correct output from $1, but "%d\n" won't output the decimal equivalent:
0x0C0 0
0x011 0
0x009 0
0x011 0
0x00E 0
0x008 0
0x034 0
0x001 0
0x00E 0
0x034 0
0x00F 0
0x009 0
So what am I missing? I have had it suggested that printf is different in awk than in the shell but that seemed wrong from what I read.