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

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`

/* 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.

"od -t u4" is fairly common. So try:

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

Thank you veru much.
It helps me a lot.
Very Best regards
Reza

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

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.