Converting an application/octet-stream file to ASCII

Recently, I came across a weird issue where an output from our UNIX based service renders a file type of “application/octet-stream”.  To confirm this, I took the file and verified it by running the ‘file’ command:

$ file -bi filename
application/octet-stream; charset=binary

Well, after a bit of reading, it turns out that our UNIX application embeds NUL characters within the file rendering it as such.  To fix this quirky issue, I ran the following command:

$ cat filename | tr -d '\0' > fixed_filename

The same ‘file’ command to confirm:

$ file -bi filename
text/plain; charset=us-ascii

Problem solved.

4 comments

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>