如何在十六进制转储输出格式字符串中包含反斜杠 \?

如何在十六进制转储输出格式字符串中包含反斜杠 \?

我想看到的:

$ printf "\U1F600\n"|hexdump -v -e '1/1 " %03o"'|tr ' ' '\\'
\360\237\230\200\012

我尝试过的:

$ printf "\U1F600\n"|hexdump -v -e '1/1 "\\%03o"'
hexdump: bad conversion character %�

$ printf "\U1F600\n"|hexdump -v -e '1/1 "\%03o"'
hexdump: bad conversion character %%

$ printf "\U1F600\n"|hexdump -v -e '1/1 "\\\%03o"'
hexdump: bad conversion character %\

$ printf "\U1F600\n"|hexdump -v -e '1/1 "\\\\%03o"'
\\\\360\\\\237\\\\230\\\\200\\\\12

答案1

基于hexdump手册页中的示例:

       # hex with preceding 'x'
       % echo hello | hexdump -v -e '"x" 1/1 "%02X" " "' ; echo
       x68 x65 x6C x6C x6F x0A

看来你可以使用-e '"\\" 1/1 "%03o" '

前任。

$ echo hello | hexdump -v -e '"\\" 1/1 "%03o" ' ; echo
\150\145\154\154\157\012

相关内容