strtonum in OS X, not found

故事扮演 提交于 2019-12-24 06:47:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!