Using awk
To use GNU awk to convert hex to decimal:
$ echo '0xFFFFFFFE' | awk -n '{printf "%i\n",$1}'
4294967294
Or:
$ x='0xFFFFFFFE'
$ awk -n -v x="$x" 'BEGIN{printf "%i\n",x}'
4294967294
Or:
$ x='0xFFFFFFFE'; awk -v x="$x" 'BEGIN{print strtonum(x)}'
4294967294
To convert hex to decimal using bash:
$ echo $((0xFFFFFFFE))
4294967294
Limitations:
1. GNU awk is limited to 52-bit integers.
2. The above could be extended to perform two's-complement arithmetic but it hasn't.
To avoid both these limitations, see the python solution below:
Using python
Awk does not handle long integers. For long integers, consider this python script:
$ cat n.py
#!/usr/bin/python3
import sys
def h(x):
x = int(x, 16)
return x if x < 2**63 else x - 2**64
for line in sys.stdin:
print(*[h(x) for x in line.split()])
Let's use this input file:
$ cat file
FFFFFFFFFFFFFFFF EFEFEFEFEFEFEFEF
When we run our script, we find:
$ python3 n.py <file
-1 -1157442765409226769
system()command inawkis a code smell -- you're much better off not usingawkat all if you'd be pushing all the work from awk back to a shell.system()is not just inefficient, but its use runs major security risks.system()is dangerous because everything it passes is parsed as code, so malicious data can run arbitrary commands; you don't have that problem when handling data in bash unlessevalor equivalents are used, nor do you have it in native awk.