更新时间:2022-11-16 15:05:54
echo -n 5a | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie'
请注意,这不会跳过非十六进制字符.如果您只想要十六进制(原始字符串中没有空格等):
Note that this won't skip non-hex characters. If you want just the hex (no whitespace from the original string etc):
echo 5a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie'
此外,zsh
和 bash
在 echo
中原生支持:
Also, zsh
and bash
support this natively in echo
:
echo -e 'x5a'