Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape percent sign (%) in hexdump format

I'm trying to emit a hex string like:

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

but with % instead.

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

fails with

hexdump: bad conversion character %%

Is there any way to escape % in hexdump format string?

like image 661
majkrzak Avatar asked Dec 21 '25 18:12

majkrzak


1 Answers

I don't see any way to get hexdump to emit a '%' character directly. Perhaps you could continue to emit the '_' character and then pipe the result through sed to convert the '_' into a '%'. Something like this:

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

which produces:

%68%65%6C%6C%6F%0A
like image 170
ottomeister Avatar answered Dec 24 '25 11:12

ottomeister



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!