5

I have read many similar question on the Stack Exchange community but none of them address a 'clean' binary dump. I have used: xxd and sed combinations to try to obtain a clean binary dump from any given file.

Let me explain what I'm talking about. You have probably seen the output of `xxd -p', it looks something like this:

f4d37fd532171a4a3445be1bb03e7d6b75f3871ffee937aebc9eb2c9417f
f4e2fc8516e0a60a2c7e83c6a14c1a5e1b1e3f2ab9e12904cbd18aa2a4b9
f493d317c7a3ce71b7ab99fad4b64431d34866ced4d1f3e3f38136860009
fd08800c90491c8f7230d8b07936c4c0c29d2d12b138cdb2c544be9cc9fa
0e79d66faf375737966b67e7c7bf7efcf1703616a4643193d9aaafd63215
cf09a6e3e152bd01e9696b79f5faa5edd9f9b05628fdd9f77ee0dae1c5e8
dc2351d59693d84abac088cc4cd72916b5499830e4482e214bda0892f38c
60e9856fa111172a529222a7905e20b3c272a5b25c6fec9fbe386bb7f6cf

There are no line numbers, no corresponding ASCII, nothing. Just plain old collection of bytes. That is the thing I'm after, except that I need the binary.

There are two options: I could first obtain a plain xxd hex dump like the one shown above and convert that to binary, OR may be there's some tool or utility in bash that I don't know about that could do this.

This is what I want: A binary dump looks like this:

001101100011010100110110001100010011100001100001
011000010011000000111001011001000011010100110010
001101000011001101100001011000110110010100110000
001100100110010001100001001100000011010100110011
001110000110011000111001011000100110000100110010
011001010110010000110011001100010110001100001010

Any of the above is fine to me, as long as I obtain a clean plain binary dump from any file. So, my question is how do I obtain it--without any linebreaks or spaces or line numbers or nothing?

closed as off-topic by Michael Homer, Satō Katsura, Jeff Schaller, EightBitTony, phk Jun 5 '17 at 11:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Michael Homer, Satō Katsura, Jeff Schaller, EightBitTony, phk

5

A pragmatic solution with xxd, cut and tr:

xxd -b -c1 file | cut -d" " -f2 | tr -d "\n"
0

A perl solution:

perl -ne 'use bytes; while ($a=substr $_,0,1,"") {printf "%08b\n", ord $a}'

Remove the \n for everything in one long run-on print.

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