Operating System - HP-UX
1820389 Members
3864 Online
109623 Solutions
New Discussion юеВ

How to convert binary file to ASCII

 
Glenn Morton_1
Occasional Advisor

How to convert binary file to ASCII

This should be an easy one.
I can't seem to find a command to convert my
binary file to ASCII.
7 REPLIES 7
Jeff Schussele
Honored Contributor

Re: How to convert binary file to ASCII

Hi Glenn,

There is no standard command in HP-UX to do this.
There is a pkg btoa on the porting center that purports to do this. Here's the link:

http://hpux.cs.utah.edu/hppd/hpux/Misc/btoa-5.2/

I've never used it, though.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Patrick Wallek
Honored Contributor

Re: How to convert binary file to ASCII

As Jeff said, there is no standard unix command to do this.

You can use the 'strings' command to see what printable characters are in the binary file. Do a 'man strings' for more details.
A. Clay Stephenson
Acclaimed Contributor

Re: How to convert binary file to ASCII

Earth to Glenn:

Depending upon the layout of your binary file, this can be a far from trivial task. As mentioned, if it's easy you can use the strings command to recognize portions of your data (if the strings are encoded as ASCII rather than EBCDIC) or you can use the od command with various options to display integers, charaters, etc. The real problem comes in coverting the 1st 8 bytes of record to floating-point, the next 2 bytes as a short unsigned integer, the next 4 bytes as a signed integer, the next 6 bytes COBOL COMP data, and the next 30 characters as a string, .... . If that is the case the it's time to do real programming (at a minimum Perl but usually C or C++).

Just knowing the exact layout of each record is the first hurdle (and just hope you don't have to deal with variable length records).
If it ain't broke, I can fix that.
Glenn Morton_1
Occasional Advisor

Re: How to convert binary file to ASCII

Thanks everyone. Now I understand why I could not find the command.
Frank Slootweg
Honored Contributor

Re: How to convert binary file to ASCII

Well, it depends what you want to do *with* the converted file, but there *is* a standard *HP-UX* command: vis(1).

With the "-n" option of vis and inv, you can make a simple binary editor:

vis -n file.txt
vi file.txt
inv -n file.bin
Rory R Hammond
Trusted Contributor

Re: How to convert binary file to ASCII


It would be helpful if you defined what you mean by a binary file.
text, database, archive, executable, pdf, jpeg etc..

If you mean text files transported into your system useng ftp. it is sometime usefull to do so by using the binary option. inorder to preserve CR/LF (carraige returns-linefeeds) or
LF
or
CR
MSDOS uses CR/LF
UNIX uses LF
MAC uses CR.

If your intent is to convert a
"binary" MSDOS text file to a UNIX text file. There are all kinds of ways (tr, sed, awk, perl).

PDF, DATABASE and compressed files would require some els

Rory
There are a 100 ways to do things and 97 of them are right
Ryan Green
Valued Contributor

Re: How to convert binary file to ASCII

You could use uuencode(1). It will convert binary to ascii for email transmission.

ryan