One of the my servers gives me data with Content-Type: application/binary, i.e data that I am getting looks like some alien data.

Now I need to convert that data into plain data, but I am not aware of any way to do that. I am trying to do this using the command line.

After googling, I found one way: I need to delete the first 10 char and last 8 char from my data and then use gunzip with that. Then I will get the original data. But when I try to delete those characters, as it is binary output, it cuts more than that or less than 10+8 characters.

Actually echo is not able to print the data properly. So, please, does anyone know how to handle binary data?

closed as unclear what you're asking by Gilles, slm, jasonwryan, terdon, Anthon Nov 27 '13 at 4:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • The binary data is in zip format – MDThakkar Nov 26 '13 at 4:54
  • 1
    You should explain the difference between plain data and alien data. – jordanm Nov 26 '13 at 5:58
  • i mean unreadable data by alien data, plain data means readable data, i m getting data just like:mU;??H%W??xA???ZQ???z???&4????????H?jl??c?3ǟ?$?G?#?)h??xKCMM?t??_ ?D?K?L?X??u{?3s??9'o}??/|???o?+?r?T?5J??o?????on???Tl???C|?X?1?h???(?t???q??5?. %b\y??:'Ƿ?M?ԋ?=E?t,?1"??R??(??u????P?)??v?3Su???u?{?K-0 ??BD?????>??׿i8f???R??R#h????.?VMa???RI?c?0^???ZP?*'?y??????a2??6LJlw????zP?LQ{-铜??)J???9 ?@???E?szA????EU???gi?.g=,9??@???IJ??#?j?޼???/~vͼ?lFC,?A\X-?J?p??dr8????DQ??? ?BঌG????i?Zu????A//k(-??i?K?I?14\n #~C?ǡ#@?i?<? – MDThakkar Nov 26 '13 at 6:27
  • 3
    Readable by what? – jordanm Nov 26 '13 at 6:43
  • if i remove first 10 and last 8 characters and pass it into gzinflate,it gives me readable data, i.e you can understand that data,above code is trimmed(as it is too much long data) – MDThakkar Nov 26 '13 at 6:45

What your asking is quiet unclear. what format is your file ? compressed file ? archive? compressed archive ? what the command

file yourfilename

give as output ? as it's binary data, what do you want to strip octect , bit ?

to strip binaries file you should considere the use of dd command

dd if=input.bin of=output.bin bs=1 skip=X count=Y

Where X is the number of bytes you want to remove from the beginning, and Y is the number of bytes you want to process before the end of file.

Suppose you have a binary files which is 100 bytes in size and you want to remove the first 10 bytes and the last 5 bytes, obtaining an 85 bytes output. The value of X will be 10, while the value of Y will be 85 (=100-10-5). You can find file size with a simple "ls" or "wc -c" command.

Good luck


The trailing characters can be ignored, you may just get a warning, so there is half the problem, so let's look at the first 10.

now the problem can be handled by dd. all we need to do is to tell it to skip one block of 10 bytes. wget -o - http://example.com/sample-data |dd ibs=10 skip=1 of=data.zip; unzip data.zip

  • got the error as: Archive: data.zip End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of data.zip or data.zip.zip, and cannot find data.zip.ZIP, period. – MDThakkar Nov 26 '13 at 6:13
  • If i am doing the same thing with php, and after removing first 10 and last 8 characters, if i apply gzinflate(data) command, then it is giving me perfect output as i want, – MDThakkar Nov 26 '13 at 6:16
  • Jordanm said it was in zip format but gzinflate uses gzip format, so change the unzip in my answer to gunzip. – hildred Nov 26 '13 at 6:24
  • @MDThakkar you can also run php from the commandline. – hildred Nov 26 '13 at 6:25
  • ya i have tried ur code with gunzip then it is giving me gzip: data.gz: not in gzip format – MDThakkar Nov 26 '13 at 6:38

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