Converting binary file to text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Converting binary file to text file
# 1  
Old 01-22-2016
Converting binary file to text file

Hi,

Im wondering how I can convert a binary file to a text file?
I have ran the following command to output which type of binary file coding it is

Code:
od -t x1 -c eHat.data0 | head -20

and that gives me the following output;
Code:
0000000 5c 00 00 00 cd 06 f2 41 00 00 00 c6 00 00 00 c6 \ \0 \0 \0 315 006 362 A \0 \0 \0 306 \0 \0 \0 306
0000020 42 8f 95 c0 19 d5 5a c2 8e 99 1f c1 91 03 94 41 B 217 225 300 031 325 Z 302 216 231 037 301 221 003 224 A
0000040 f7 7e cd 40 c4 cc d2 be 00 00 00 c6 00 00 00 c6 367 ~ 315 @ 304 314 322 276 \0 \0 \0 306 \0 \0 \0 306
0000060 00 00 00 c6 6c d9 91 3e b6 9c 2c 3e 5b 98 63 3e \0 \0 \0 306 l 331 221 > 266 234 , > [ 230 c >
0000100 84 61 c1 3e 29 ec 6d 3e 10 9e 4d 44 00 00 00 c6 204 a 301 > ) 354 m > 020 236 M D \0 \0 \0 306
0000120 00 00 00 c6 e2 c3 79 44 c2 50 b6 43 bd ab 9a 40 \0 \0 \0 306 342 303 y D 302 P 266 C 275 253 232 @
0000140 5c 00 00 00 5c 00 00 00 00 00 00 c6 00 00 00 c6 \ \0 \0 \0 \ \0 \0 \0 \0 \0 \0 306 \0 \0 \0 306
0000160 00 00 00 c6 00 00 00 c6 00 00 00 c6 00 00 00 c6 \0 \0 \0 306 \0 \0 \0 306 \0 \0 \0 306 \0 \0 \0 306
*
0000300 00 00 00 c6 5c 00 00 00 5c 00 00 00 00 00 00 c6 \0 \0 \0 306 \ \0 \0 \0 \ \0 \0 \0 \0 \0 \0 306
0000320 00 00 00 c6 00 00 00 c6 83 08 a8 c2 82 d2 25 c3

Is there a way I can convert this to a text file?
Many thanks!

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags not only for code but also for terminal output and file contents. Thank you.

Last edited by bakunin; 01-22-2016 at 06:57 PM..
# 2  
Old 01-22-2016
I'm afraid above is NOT the binary representation of a well-formed text file (many zero bytes, mal-formed multibyte chars, malformed single byte chars, ...).
While
Code:
awk '{for(i=2; i<=NF; i++) printf "%c", 0+sprintf ("%d", "0x"$i)}' file
Col1 Col2 Col3 Col4
ABC 00000001 15-Dec-15 13000
ABC 00000001 31-Jan-16 13500
.
.
.

would reconstruct an ASCII file, the result of it applied to every other line of your file yields
Code:
\��A��B��ZŽ����A�~�@��Ҿ���lّ>��,>[�c>�a�>)�m>�MD����yD�P�C���@\\������c

A few chars are recognizable ("\", "A", "B", etc), but the main part is garbage.
# 3  
Old 01-22-2016
Quote:
Originally Posted by dp0b
Im wondering how I can convert a binary file to a text file?
What a "binary file" and what a "text file" is is primarily determined by the files contents. So there is no "conversion" between the two, like "convert CSV to Excel format". The latter is just two representations of the same thing - tabular data - but the former are simply different types of contents.

There are (today rather unusual) meanings of "text file" as containing compiled code (calling a relocatible object file before linking "text" was the IBM speak of the seventies) and if you are using the term this way you will have to use a linker. If you are using "text" in the more common meaning of "sequences of characters transporting meaning to a reading human" then there is no (common!) way to transform one into the other.

There are of course programs which use binary representations for text files (simpliest example is a packing program which packs a text file into something binary). In such a case you need to specifically reverse the algorithm (i.e use an unpack-program to restore the text file), but this means to know the used algorithm first. And even this only works if a text file was packed beforehand. Put a binary file in and another binary file will come out, packing or no packing.

If you want to search for text parts inside a binary file, this is possible: use the strings command to list readable strings within otherwise binary files:

Code:
strings /path/to/file

I hope this helps.

bakunin
# 4  
Old 01-22-2016
This looks like packed decimal to me.
The fields that look like '00 00 00 c6' appear to be cobol S9(7) COMP 3.
And on your machine, the hd program reverses the digits in each byte so that it is probably
0000006c on disk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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. (8 Replies)
Discussion started by: baranisachin
8 Replies

2. Shell Programming and Scripting

Converting text file in a matrix

Hi All, I do have a file with many lines (rows) and it is space delimited. For example: I have a file named SR345_pl.txt. If I open it in an editor, it looks like this: adfr A2 0.9345 dtgr/2 A2 0.876 fgh/3 A2 023.76 fghe/4 A2 2345 bnhy/1 A3 3456 bhy A3 0.9876 phy A5 0.987 kdrt A5... (9 Replies)
Discussion started by: Lucky Ali
9 Replies

3. UNIX for Dummies Questions & Answers

[AIX] Binary file warning for text file.

Hello guys, We had to move from a DC to another, and we are now facing an "issue" with some text files. Looks like that some of our log files are set as binary: file TuxConnectorURA.20121012 TuxConnectorURA.20121012: data or International Language text less TuxConnectorURA.20121012... (2 Replies)
Discussion started by: EnioMarques
2 Replies

4. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Shell Programming and Scripting

Converting columns of a text file.

Not sure the most effient way to do this. I have figiured out how to extract columns with shell script, but not sure how to convert This is what I have... NEWDNS 04-Jun-2011 06:00:59.762 10.220.136.217 crl.verisign.com This is what I need.... Change date, remove mil seconds,... (1 Reply)
Discussion started by: mrlayance
1 Replies

6. UNIX for Dummies Questions & Answers

Converting binary file to readable format in Ksh

In Unix/Ksh, when I try to look inside a file it says that the file may be a binary file and if I want to see it anyway. When i say 'yes', it shows me the content filled with unreadable symbols (looks like binary). Is there a command that I can run from the Unix prompt to convert/translate that... (3 Replies)
Discussion started by: arthurs
3 Replies

7. Shell Programming and Scripting

convert binary file into text file

im looking for anothr way to convert binary file into text file im using old solaris version (exatcly like xxd -r) thanks (2 Replies)
Discussion started by: modcan
2 Replies

8. Shell Programming and Scripting

Converting a text file to HTML

Hi, I need to convert a text file formatted like this ("tshark -z conv,ip" output) to HTML: ===================================================================================================== IPv4 Conversations Filter:<No Filter> | <- ... (4 Replies)
Discussion started by: ph0enix
4 Replies

9. UNIX for Dummies Questions & Answers

How to convert binary Unix file to text

Hi all, I have a print control file (dflt) for Oracle which is in binary. As I am going to develope an application in Window environment, I would like to reference the dflt file. But it is in binary format and I cannot access it. Anyone can suggest me how to convert the file into text or... (5 Replies)
Discussion started by: user12345
5 Replies

10. Shell Programming and Scripting

Converting a text file to a csv file

I have a text file that is the output of a Netbackup report. The file it generates is just a plain text file with only white space between fields. For example: Date Policy Type Kilobytes Retention 12/5/2005 WinNT Full 18329948 6 Months I... (4 Replies)
Discussion started by: primowalker
4 Replies
Login or Register to Ask a Question