[prog] Reading data file

dominik.schramm at gmxpro.net dominik.schramm at gmxpro.net
Sun Jan 25 13:24:22 EST 2004


Hi,

"Daniel." <cristofd at hevanet.com> writes:
> Thinking about it, that probably is not a job for bash but for some
> program running under bash's control. I don't know what the standard
> UNIX program (as opposed to a system call) to do "get the Xth 32-bit
> int from file Y" would be--anyone?--but it would be trivial to write
> one in C anyway. It would introduce a lot of overhead, and someone
> interested in making a really good-quality mail-exporting program to
> be used by many people would probably abandon bash right now, but it
> should get the job done; if nobody suggests a pre-existing program,
> I'll write one.

There has been a thread about roughly the same topic a while ago
on Techtalk (?). (I couldn't find it with Google, though).
There, the program "od" was suggested -- which is short for
octal dump -- it dumps files in octal/decimal/hexadecimal/whatever
format. This may be useful here.
In Debian, od comes with the "textutils" package.

Consult the man page od(1) for details, because
usage is a little awkward, if I remember correctly. 

This command line seems appropriate for your application:
$ od -j 4 -t x4 -w8 binaryfile

meaning: 
-j 4: skip 4 bytes (32 bits) from input before outputting,
      i.e., omit the 32bit version header

-t x4: output 4byte headecimal numbers

-t u4: output 4byte unsigned decimal numbers

-w8: display 8 bytes of input per output line, i.e. the 32bit
     message id and its 32bit message attribute number 
     (note: no space between w and 8)

Then you can interpret the output with cut (returning the
desired number) and bash arithmetics. bash can handle hexadecimal
numbers, just prefix them with "0x".

hope this helps
regards
dominik

-- 
Dominik Schramm <dominik.schramm at gmxpro.net>
pgp key available via e-mail, web, and FTP from 
http://www.cam.ac.uk.pgp.net/pgpnet/wwwkeys.html



More information about the Programming mailing list