msh210
msh210

Reputation: 272

Convert a byte to something human-readable

I've got a file consisting of a bunch of 'rows' of data (not actually on separate lines). As far as I can tell from the description (PDF), each 'row' has forty bytes precisely, as follows:

And there's nothing else in the file (no file header, for example). (I may well be wrong in my understanding of the linked-to documentation, and would appreciate any correction; more info may be available elsewhere (PDF).)

I wish to:

  1. convert each byte representation of a number to a human-readable representation of the number and each 00 byte to (say) a human-readable 0, and
  2. convert the file to comma-separated or the like.

Now, step (2) should be doable using sed; I mention it only because I want to make sure step (1) is done is such a manner as to allow step (2) (for example, keep track of how many bytes are each field when doing step (1)). But step (1) I have no idea how to do. Can anyone help?

As a caveat, please note that I'm comfortable with sed and bash and can handle perl, but have no experience with real programming; and that, alas, I'm doing this on a Windows machine I don't have installation-of-programs rights on, so (although I have a sed port) I don't have bash. So, basically, I need to do this in sed or a Windows (DOS) command-line script. (I should be able to download the files to another machine, work with them, and upload them, though, if that turns out to be necessary.)

Upvotes: 1

Views: 434

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176688

Perl has an unpack function you could use.

Upvotes: 1

Related Questions