Need to convert Binary files to ascii


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Need to convert Binary files to ascii
# 1  
Old 10-09-2004
Need to convert Binary files to ascii

Dear Experts
I need to read a binary file. I know for example in byte number 3801-3804 there is a 4 byte number embeded. Is there a way to extract this number from this file and then convert it to ascii via unix??
Your help would be highly appreciated.
Very Best Regards
Reza

Last edited by Reza Nazarian; 10-09-2004 at 09:24 AM..
# 2  
Old 10-11-2004
od will jump to an offset with the -j <offset> qualifier.
The -t u4 will tell od to format the output as an unsigned decimal.

You need to check your od man page because I think the -t qualifier is not always supported, and may only support 16 bit words, not 32 bit words.

Otherwise compile and try this
cc -o bfile bfile.c
bfile `head -c -n 3404 mybinaryfile`

Code:
/* bfile.c */
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
     if (*argv[1])
     {
         if(strlen(argv[1])>3403)
         {
                 char  *p=&argv[1][3401];
                 fprintf(stdout,"%d\n",*(int *)p);
         }
      }
      return 0;
}

You are limited in postion in the file to what _POSIX_ARG_MAX is defined to for your system (in limits.h) - Normally it is 4096.

Last edited by jim mcnamara; 10-11-2004 at 12:27 PM..
# 3  
Old 10-11-2004
"od -t u4" is fairly common. So try:

dd if=datafile bs=1 skip=3800 count=4 | od -t u4
# 4  
Old 10-11-2004
Thank you veru much.
It helps me a lot.
Very Best regards
Reza
# 5  
Old 10-20-2004
Friends,

I've tried on solaris, but I could n't find ascii

dd if=binaryinputfile bs=1 skip=3800 count=4 | od -t u4

output :

INDBU3:/usr/users/FTAMUSER/kk $
dd if=SMP20041006173649188151 bs=1 skip=3800 count=4 | od -t u4
4+0 records in
4+0 records out
0000000 0000000000
0000004


Pls help me to convert binary to ascii on solaris.

Thanks
Krishna
# 6  
Old 11-05-2004
Quote:
dd if=binaryinputfile bs=1 skip=3800 count=4 | od -t u4
Krishna,

The above command will work only if:

1. In the binary file, there is a 4 byte number embeded in bytes 3801-3804.

And remember, it will just give you the Integer present at that location. It won't convert the binary file into text file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

2. Solaris

ASN Binary to ASCII

Dears, I need help to convert the binary file into ASCII format. Actually we have CDRs which is generated by telecom switch at this is in ASN1 format or binary format, I need to convert those binary formatted file into ASCII format using Perl, or shell scripting. Is there any way to solve... (3 Replies)
Discussion started by: PRINCESS_RORO
3 Replies

3. Solaris

Convert files from binary to ASCII

I have a huge files in binary format thanks to help me in finding a way to convert these files from Binary format to ASCII format. (0 Replies)
Discussion started by: PRINCESS_RORO
0 Replies

4. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

5. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

6. UNIX for Dummies Questions & Answers

Ascii or Binary?

Hello all, I am working with ftp servers in unix, and always I have to get and put files but I don't know exactly if I have to get or put them as an ascii or binary. Some files that I use are: .txt, .sav, .fmb, .pct, .sh, .ksh, .dat, .log. Somebody can tell me what is the difference between... (2 Replies)
Discussion started by: Geller
2 Replies

7. Shell Programming and Scripting

binary to ascii

Hi, Is there a way to convert the binary file to ascii . the binary file is pipe delimited. from source the file(pipe delimited) is ftped to mainframe and from mainframe it is ftped to the unix box using binary format. Is there a way to change it back to ascii and view it? Thanks! (3 Replies)
Discussion started by: dnat
3 Replies

8. UNIX for Advanced & Expert Users

Convert Binary data to ascii data

Friends, I've tried on solaris, but I could n't get ascii data dd if=binaryinputfile bs=1 skip=3800 count=4 | od -t u4 output : INDBU3:/usr/users/FTAMUSER/kk $ dd if=SMP20041006173649188151 bs=1 skip=3800 count=4 | od -t u4 4+0 records in 4+0 records out 0000000 0000000000 0000004... (4 Replies)
Discussion started by: krishna
4 Replies

9. UNIX for Advanced & Expert Users

Convert ASCII to BINARY

Here is what I did . . . . I FTP'd several *.pdf files from a web site to a UNIX server, and did not set the transfer mode to BIN, now Adobe thinks that the documents are corrupted. Is there a way to convert the *.pdf files to Binary so that Adobe can open them again. I would just re-download... (2 Replies)
Discussion started by: pc9456
2 Replies

10. UNIX for Advanced & Expert Users

viewing binary files in ASCII

Hi, How to view binary files in ASCII format.???????????????? Bye (2 Replies)
Discussion started by: manjunath
2 Replies
Login or Register to Ask a Question