How to change the default line length for od and hexdump

10,786

Solution 1

od has the --width=N argument, which you can use to choose how many bytes per line, perhaps that's what you're looking for? hexdump has a -e FORMATSTRING which has promise, but I've never played too much with it.

Solution 2

I know this is an old question, but for completeness, here is an example hexdump command that prints 8 bytes per line:

hexdump -e '8/1 " %02X" "\n"' <file>

More information about hexdump format strings can be found at these links:

Solution 3

I found the way to make -C | --canonical like but width-wide

hexdump -e '"%08_ax " '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))'/1 "%02x " " |" '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))'/1 "%_p" /0 "| \n"'

just change '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))' to your value

Share:
10,786

Related videos on Youtube

newenglander
Author by

newenglander

Updated on September 18, 2022

Comments

  • newenglander
    newenglander almost 2 years

    Is there any way to change the default line length for the od and hexdump commands? Can't see anything apropriate in the man pages.

  • Thor
    Thor about 12 years
    @newenglander as mentioned under SEE ALSO you should also check info coreutils 'od invocation'.
  • jsbillings
    jsbillings about 12 years
    With anything GNU, it's always a good idea to check the info page. It has much more information.
  • newenglander
    newenglander about 12 years
    Thanks for the extra tip, my SEE ALSO only had hexdump(1), strings(1).
  • newenglander
    newenglander about 12 years
    Calling info coreutils 'od invocation' on my systems (Mac OS X, FreeBSD) gives me the message No menu item 'coreutils' in node '(dir)Top'. But I did try it on Linux and it was indeed more helpful (but then again so was the man page on that system).
  • jsbillings
    jsbillings about 12 years
    @newenglander: The od and hexdump on MacOSX isn't the GNU version, but BSD. They're different implementations than the GNU utilities, so no info pages. Good to hear that the --width argument works.
  • Admin
    Admin about 2 years
    Good digging - thanks for this!