![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ascii to binary conversion in sco 5.0.5 | sameek1211 | SCO | 1 | 12-17-2007 07:49 AM |
| Convert Binary data to ascii data | krishna | UNIX for Advanced & Expert Users | 4 | 11-05-2004 04:12 PM |
| text files, ASCII files, binary files and ftp transfers | Perderabo | Answers to Frequently Asked Questions | 0 | 04-08-2004 04:25 PM |
| Convert ASCII to BINARY | pc9456 | UNIX for Advanced & Expert Users | 2 | 06-24-2002 06:46 AM |
| viewing binary files in ASCII | manjunath | UNIX for Advanced & Expert Users | 2 | 04-02-2002 08:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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 08:24 AM.. |
|
||||
|
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;
}
Last edited by jim mcnamara; 10-11-2004 at 11:27 AM.. |
|
||||
|
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 |
|
||||
|
Quote:
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|