问题
cmp -l "$1" "$2/$1" | awk '{printf "%08X %02X %02X\n", $1, strtonum(0$2), strtonum(0$3)}'
I am using command above to show the binary differences in Ubuntu, from shell script. However, this doesn't work in OS X lion, claiming that strtonum not found. Any idea how to have it in OS X or substitute it with something similar/light?
回答1:
Either MacPorts or Homebrew can be used to install the GNU version of awk
which includes strtonum
. To avoid conflicts with the system awk
, they install the GNU version as gawk
.
For example, with the base MacPorts
files installed:
sudo port install gawk
回答2:
As it was said there is no strtonum
on mac/BSD awk
, but if you need to convert hex
to dec
there is a workaround:
echo 0xff | awk '{print $1+0}'
So just add 0
to hex value and by default awk
converts it to decimal value.
来源:https://stackoverflow.com/questions/8199934/strtonum-in-os-x-not-found