十六进制转储格式的转义百分号(%)

问题描述 投票:1回答:1

问题

我正在尝试发出一个十六进制字符串,例如:

echo hello | hexdump -ve '/1 "_%02X"' ; echo

但使用%代替。

实际vs预期

echo hello | hexdump -ve '/1 "%%%02X"' ; echo

失败

hexdump: bad conversion character %%

问题

有没有办法以十六进制转储格式的字符串转义%

text-processing hexdump
1个回答
0
投票

我看不到有任何方法可以使hexdump直接发出'%'字符。也许您可以继续发出'_'字符,然后将结果通过sed传递给[_]转换为'%'。像这样的东西:

echo hello | hexdump -ve '/1 "_%02X"' | sed -e 's/_/%/g'

产生:

%68%65%6C%6C%6F%0A
© www.soinside.com 2019 - 2024. All rights reserved.