0

I'm trying to get the output of my hexdump command to look similar to hexedit default. I've been playing with the format strings using -e, but since there are not very good documentation, that visually describe how to use it, I am failing to get it right.

Currently, I have:

# hexdump -C -n 0x100 m1.bin
00000090  00 00 00 00 00 56 08 00  00 00 00 00 04 00 00 00  |.....V..........|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

But I would like to have it with one more space separating the 4 bytes, like this:

00000090  00 00 00 00  00 56 08 00  00 00 00 00  04 00 00 00  |.....V..........|
000000a0  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  |................|

alternatively like this:

00000090  0000 0000  0056 0800  0000 0000  0400 0000  |.....V..........|
000000a0  0000 0000  0000 0000  0000 0000  0000 0000  |................|

Also, if it would be possible to get some color, that would be really great. So far I haven't been able to get any color at all from hexdump.

EDIT

Also great for piping is to leave out address, char field and newlines (\n) with:

# hexdump -e '16/1 "%04.2x"' -n 40 m1.bin
  54  4f  43  00  00  00  00  00  00  00  00  00  00  00  00 ...
2

Not that simple nor obvious... try

 hexdump -v  -e '"%08.8_ax  "' -e' 4/1 "%02x " "  " 4/1 "%02x " "  "  4/1 "%02x " "  " 4/1 "%02x "  ' -e '" |" 16/1 "%_p" "|\n"' file
  • That is insane! Ok, thank you so much for that, it must have taken you a lot of trial and error. I owe you a drink! – not2qubit Oct 17 '18 at 22:27
  • Actually, as always in IT and life, once you've understood the principle, it's getting easier and faster. – RudiC Oct 17 '18 at 22:31
  • Yeah, I just got the hang of it and the coloring of byte-sequences is very cool. I wish the man pages would have had better examples, as it would have saved me years of piping to grep using custom terminal color settings. – not2qubit Oct 24 '18 at 9:03
-1

Instead of using hex dump I would suggest using xxd like this:

xxd <bin_name>
00000000: cffa edfe 0700 0001 0300 0080 0200 0000  ................
00000010: 1000 0000 d006 0000 8580 2100 0000 0000  ..........!.....
00000020: 1900 0000 4800 0000 5f5f 5041 4745 5a45  ....H...__PAGEZE
00000030: 524f 0000 0000 0000 0000 0000 0000 0000  RO..............
00000040: 0000 0000 0100 0000 0000 0000 0000 0000  ................

If you want | around the ascii letters at the last, try this:

xxd <bin_name> |  sed -r 's/(................)$/|\1|/g'
00000000: cffa edfe 0700 0001 0300 0080 0200 0000  |................|
00000010: 1000 0000 d006 0000 8580 2100 0000 0000  |..........!.....|
00000020: 1900 0000 4800 0000 5f5f 5041 4745 5a45  |....H...__PAGEZE|
00000030: 524f 0000 0000 0000 0000 0000 0000 0000  |RO..............|
00000040: 0000 0000 0100 0000 0000 0000 0000 0000  |................|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.