awk to remove leading zeros for a hex number

Is it possible by using awk to remove leading zeros for a hex number?

ex:
0000000011179E0A -> 11179E0A

Thank you!

$ echo 0000000011179E0A | awk '{print gensub(/^0*/,"","")}'
11179E0A
1 Like
$ echo 0000000011179E0A | ruby -e 'print gets.sub(/^0*/,"")'
11179E0A

1 Like

Convert to base 10 using bash/ksh base conversion and back to hex with printf:

$ printf "%X" $((16#0000000011179E0A))
11179E0A

Edit: Beware - After more testing of the above I found it dosn't work real well with big hex numbers (particularly if first hex digit is > 8), probably best to use string functions to remove the zeros:

 $ echo 0000000011179E0A | sed 's/^0*//'
11179E0A
1 Like
echo "0000000011179E0A" | sed 's/^0*//'
1 Like