I think this workaround warrants a mention in the manpage. I adjusted an example in debian/patches/hexdump_man.diff accordingly, see the attachment.
Maybe it should also say somewhere that in order to output a literal backslash it must be put onto a separate format unit.
Description: Add examples to manpage. Author: Michael Meskes <mes...@debian.org> --- freebsd/usr.bin/hexdump/hexdump.1.orig 2010-11-03 19:36:36.000000000 +0100 +++ bsdmainutils/usr.bin/hexdump/hexdump.1 2010-11-03 19:37:44.000000000 +0100 @@ -197,7 +197,7 @@ .Xr fprintf 3 default which prints the entire string if the precision is unspecified). .It -The conversion characters ``h'', ``l'', ``n'', ``p'' and ``q'' are +The conversion characters ``%'', ``h'', ``l'', ``n'', ``p'' and ``q'' are not supported. .It The single character escape sequences @@ -346,6 +346,49 @@ "%07.7_Ax\en" "%07.7_ax " 8/2 "%04x " "\en" .Ed +.Pp +Some examples for the \-e option: +.Bd -literal -offset indent +# hex bytes +% echo hello | hexdump \-v \-e '/1 "%02X "' ; echo +68 65 6C 6C 6F 0A + +# same, with ASCII section +% echo hello | hexdump \-e '8/1 "%02X ""\\t"" "' \-e '8/1 "%c""\\n"' +68 65 6C 6C 6F 0A hello + +# hex with preceding '\\x' +% echo hello | hexdump \-v \-e '"\\\\" 1/1 "x%02X" " "' ; echo +\\x68 \\x65 \\x6C \\x6C \\x6F \\x0A + +# one hex byte per line +% echo hello | hexdump \-v \-e '/1 "%02X\\n"' +68 +65 +6C +6C +6F +0A + +# a table of byte#, hex, decimal, octal, ASCII +% echo hello | hexdump \-v \-e '/1 "%_ad# "' \-e '/1 "%02X hex"' \-e '/1 " = %03i dec"' \-e '/1 " = %03o oct"' \-e '/1 " = _%c\\_\\n"' +0# 68 hex = 104 dec = 150 oct = _h_ +1# 65 hex = 101 dec = 145 oct = _e_ +2# 6C hex = 108 dec = 154 oct = _l_ +3# 6C hex = 108 dec = 154 oct = _l_ +4# 6F hex = 111 dec = 157 oct = _o_ +5# 0A hex = 010 dec = 012 oct = _ +_ + +# byte# & ASCII with control chars +% echo hello | hexdump \-v \-e '/1 "%_ad# "' \-e '/1 " _%_u\\_\\n"' +0# _h_ +1# _e_ +2# _l_ +3# _l_ +4# _o_ +5# _lf_ +.Ed .Sh SEE ALSO .Xr gdb 1 , .Xr od 1