Recreate hexdump -C format as -e argument

40 Views Asked by At

I am trying to recreate the format that hexdump -C will output, namely

00000000  50 4b 03 04 2d 00 04 00  08 00 16 b5 ea 56 99 f1  |PK..-........V..|
00000010  ef 29 ff ff ff ff ff ff  ff ff 0f 00 30 00 6e 61  |.)..........0.na|

I'm arriving at something like

hexdump -n 200 -e '16/1 "%02x ""\t"" "' -e '"|"' -e '16/1 "%_p""|\n"' file.zip

giving

50 4b 03 04 2d 00 04 00 08 00 16 b5 ea 56 99 f1  |PK..-........V..|
ef 29 ff ff ff ff ff ff ff ff 0f 00 30 00 6e 61  |.)..........0.na|

but how do I add the extra space every 8 bytes and the offset in the file?

1

There are 1 best solutions below

0
Felix Dombek On

OK, found it: We can create groups by repeating format specifications inside the same -e block, and we output the offset with %10_ax.

For double width (32 bytes), my whole commandline now looks like:

hexdump -n 200 -e '1/1 "%10_ax""   "' -e '8/1 "%02x ""  " 8/1 "%02x ""  " 8/1 "%02x ""  " 8/1 "%02x ""  |"' -e '32/1 "%_p""|\n"' file.zip