Converting a binary file to ascii and vice versa?

Hi All,
I have a binary file which is being exported from a Database, and i need to convert that to ASCII format. How can i achieve that? And this solution should work for any file which is given to us; means they will give different files from different tables.

Thanks in advance.

strings is a rather generic way of extracting printable text from binary files:

STRINGS(1)                   GNU Development Tools                  STRINGS(1)

NAME
       strings - print the strings of printable characters in files.

What kind of "file" is it? Unless you know how to decode the file, that might be the closest you get, and there would be no vice-versa.

Hi Scoot,
THanks for the reply, As i told its a file extracted from a database table with '~' as a delimitter; The file might contain arbitrary No. of columns each time. Strings is not converting the entire file properly as expected. Is there any other command/script that will help me?

You never mentioned anything about a ~ delimiter!

Run file filename against the file. What does it say?

And what exactly do you want to do once you've "converted" it to ASCII, before you convert it back again?

Without seeing a sample of the file, and with your description and requirement being as vague as they are, I would have no idea what to suggest here.

okey
when i run file filename it gives data

Actullay converting to ASCII is enough - After converting i need to scp that file to another server and it will be consumed by some other downstream applications

The converse is just to check whether the file file has been converted properly or not.

The file will have data extracted from a table. A mix of character, date, number and everything.

Is this helpful, please lemme know if u need more details?

data is the most generic of terms and could mean anything. Assuming you mean it's the result of some SQL query, then you still need to post some of it before anyone can know what to do with it. And you need to be much more specific about what you mean by converting it to ASCII. Without knowing exactly what you mean by data and without seeing some of it, I don't know how you can expect any help here.

I will try to post some of the data, watever i have it has some PII so this is the information i have as of now

� 'Binary' = 2-byte integer, n, followed by n bytes of data. In this format:

� The data is prefixed by a record-length marker.

[LEFT]� The record-length marker does not include the length of the marker
itself.[/LEFT]
� The record-length is not part of the transmitted data.

If possible you can help me with this if not i will try to post some sample data. but if i try to open the .dat file it shows junk character is that the expected behaviour? THanks.

If the file isn't ASCII, it will look like junk. A text editor can't make sense of it because there's nothing to make sense of -- it won't know which bytes are supposed to be what data when everything's stored raw.

This is why we need the file, and a good description of it. Either by itself is only half the problem.

If it's just for file transfer, try the base64 or uuencode commands.