linuxbashbinaryfilesxxd

How do you get plain text from binary where the plaintext is formatted by itself?


Desired output of something like "xxd -b file":

00000000 00000000 00000000 00000000

00000000 00000000 00000000 00000000

..etc

then followed by

plaintext here

Actual output:

00000000 00000000 00000000 00000000 plai

00000000 00000000 00000000 00000000 n te

00000000 00000000 00000000 00000000 xt h

Hopefully communicates what I'm getting at. This is just a minor issue I encountered doing a beginner CTF, but it felt very off and sloppy to copy paste just one line at a time, since highlighting treats the actual information I want in the right column as just part the array of text. I've tried a few different flags with xxd and read the man page, but I have not found an option that outputs the plaintext by itself or in a manner that is more readable. Is there another tool I should be using, ideally one that is common on most linux distros?


Solution

  • Process the file twice, once by xxd, once by cat. Use cut to remove the plaintext from the xxd output:

    xxd -b file | cut -d' ' -f1-8 ; cat file
    

    Use 2-8 if you aren't interested in the positions.