Consider using the following program that filters hex number in the range 0x10
– 0xa0
.
echo -e "0x10n0xffn0x16n0x80n0x50" | awk '$1 >= 0x10 && $1 <= 0xa0 { print $0 }'
The program works fine, if I replace all numbers using decimal equivalents, but fails with hex numbers.
The version of awk
that I’m using doesn’t support --non-decimal-data
– it’s the default version that comes with Debian 10 Buster.
How can I make the comparison work with hex numbers?
2
Answers
awk
hasstrtonum
function for this conversion fromhex
todecimal
:In absence of
gnu awk
, you may use thisperl
one liner also:one trick is doing string comparison instead. Since "a">"9", this will work