Hexdump

如何在 hexdump 輸出格式字元串中包含反斜杠 ?

  • September 6, 2018

我想看到的:

$ 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

基於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

引用自:https://unix.stackexchange.com/questions/467310