How to create a hex dump of file containing only the hex characters without spaces in bash? How to create a hex dump of file containing only the hex characters without spaces in bash? bash bash

How to create a hex dump of file containing only the hex characters without spaces in bash?


xxd -p file

Or if you want it all on a single line:

xxd -p file | tr -d '\n'


Format strings can make hexdump behave exactly as you want it to (no whitespace at all, byte by byte):

hexdump -ve '1/1 "%.2x"'

1/1 means "each format is applied once and takes one byte", and "%.2x" is the actual format string, like in printf. In this case: 2-character hexadecimal number, leading zeros if shorter.


It seems to depend on the details of the version of od. On OSX, use this:

od -t x1 -An file |tr -d '\n '

(That's print as type hex bytes, with no address. And whitespace deleted afterwards, of course.)