gimp25 wrote:
MOT,32B,1,232E
$2 and $4 are hex and I need to convert to decimal. I've tried:
Code:
awk 'BEGIN {FS = ","}; {print $1, "0x"$2, $3, "0x"$4}; {printf "%s, %d, %s, %d\n"}'
The command line complains about the first printf string format in the third operation as being a problem.
printf() uses the format printf("<format>", <value>);
your printf function has all the format tags, but no value tags, that's why it's running our of arguments.
Why would you print everything twice anyway? (print
and printf?)
If you have GNU awk, there is a strtonum() function available to convert strings to numbers.
I think the following should help you out:
Code:
gawk -F, '{ printf("%s, %d, %s, %d\n", $1, strtonum("0x"$2), $3, strtonum("0x"$4)); }'