Output file with one byte per line in hex format (under linux bash)

bash, hexdump, output

Solution

od -An -vtx1 -w1 test.txt | cut -c2-

If you don't want newlines:

od -An -vtx1 -w1 test.txt | cut -c2- | fgrep -v 0a

Meaning of `od` options:

- `-An` : addresses: no

- `-v` : verbose, i.e., don't write a `*` instead of repeating lines

- `-tx1` : output type: hex, 1 byte (use `-tx1z` for an `hd`-like output)

- `-w1` : max width: 1

One nice thing about `od` is that it's available on any `*x` system.

Problem

As the title says, here is an example: ``` $ cat test.txt ABCD $ hd test.txt 00000000 41 42 43 44 0a |ABCD.| 00000005 ``` my desired output would be: ``` 41 42 43 44 ``` I know that this is possible with sed, awk and stuff, but this might be very slow for large files. I thought of an format string for "hexdump" or a parameter combination for "od". Could you please help me out?

Original source