Sponsored Content
Top Forums Shell Programming and Scripting Reading Numerical Binary Data using KSH Post 302244655 by otheus on Wednesday 8th of October 2008 10:51:55 AM
Old 10-08-2008
Perl. "man perlfunc" and search for "pack" and "unpack". It's quite cryptic, so I'll refer you also to ...The first has some examples for doing exactly what you want. Ultimately, you can create command-line perl scripts...

In reading binary data, the other problem you'll encounter is trying to figure out how to get it into Perl. This is not hard, but it's not obvious. As long as your datafile will easily fit in memory, this is suitable. Otherwise, you'll want to read several bytes at a time with sysread(). (Again, see man perlfunc).

Code:
perl -e 'undef $/; $dat=<>; print length($dat),"\n"; ' inputfile.binary

That reads in your binary file and prints out its size. $dat contains the entire image so now you can do manipulations on it with pack/unpack.

Last edited by otheus; 10-08-2008 at 01:12 PM.. Reason: Fixed post per drl
 

10 More Discussions You Might Find Interesting

1. Programming

Reading from a binary file

I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist? this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Discussion started by: primal
3 Replies

2. Programming

Adding files of numerical data

Hi I was hoping that maybe someone could help me with a small piece of C code. I have a number of files, which are all of similar layout ie. three lines of text and 5-6 columns of numerical data. I need to add each of the elements of the second column in one file to their counterparts in the second... (17 Replies)
Discussion started by: Boucho
17 Replies

3. Shell Programming and Scripting

How to strip non numerical data out of file?

Hi, How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers. e.g.: ######### 123 aaa124 125bbb 126 127 ######### So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except... (10 Replies)
Discussion started by: Juha
10 Replies

4. Shell Programming and Scripting

ksh numerical RegX

I need to distinguish between numerical characters in a script: echo "Enter a number." read num if (( $num = * )) ; then exit 0 fi this RegX does not work. Any suggestions? (5 Replies)
Discussion started by: prkfriryce
5 Replies

5. Shell Programming and Scripting

script to sort a string of numerical data in set fields

So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers. like: 19383882872201110929282821818182827349190102837364718191001932873711 Now, each number is part of a numerical value of... (4 Replies)
Discussion started by: tlarkin
4 Replies

6. Programming

reading binary files

#include <stdio.h> /* typedef struct { char name; int number; float balance; } acct_info_t; */ int main() { FILE *fptr; fptr = fopen("acct_info", "r"); int magic = 5; fseek(fptr,3,SEEK_SET); fread(&magic,sizeof(int),1,fptr);... (7 Replies)
Discussion started by: robin_simple
7 Replies

7. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies

8. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

9. UNIX for Dummies Questions & Answers

Divide a numerical data column by a variable

Hello, I have two files, f1 and f2. f1 has 5 columns like so: a b c d 154 e f g h 365 ..... f2 has two columns, the first column contains the name of the above file and second column contains a constant which is to be used for division. e.g. file1 56 I want to divide the 5th... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

10. Solaris

Reading binary content

Dear Gurus I am stuck with the peice of work and do not know from where to start. I get a machine generated file which is binary file contain binary data, i want to read binary data as it is without converting into any other format. i want to read byte by byte. Please let me know what... (24 Replies)
Discussion started by: guddu_12
24 Replies
MooseX::Storage::Basic(3pm)				User Contributed Perl Documentation			       MooseX::Storage::Basic(3pm)

NAME
MooseX::Storage::Basic - The simplest level of serialization SYNOPSIS
package Point; use Moose; use MooseX::Storage; our $VERSION = '0.01'; with Storage; has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); 1; my $p = Point->new(x => 10, y => 10); ## methods to pack/unpack an ## object in perl data structures # pack the class into a hash $p->pack(); # { __CLASS__ => 'Point-0.01', x => 10, y => 10 } # unpack the hash into a class my $p2 = Point->unpack({ __CLASS__ => 'Point-0.01', x => 10, y => 10 }); # unpack the hash, with insertion of paramaters my $p3 = Point->unpack( $p->pack, inject => { x => 11 } ); DESCRIPTION
This is the most basic form of serialization. This is used by default but the exported "Storage" function. METHODS
pack ([ disable_cycle_check = 1])> Providing the "disable_cycle_check" argument disables checks for any cyclical references. The current implementation for this check is rather naive, so if you know what you are doing, you can bypass this check. This trait is applied on a perl-case basis. To set this flag for all objects that inherit from this role, see MooseX::Storage::Traits::DisableCycleDetection. unpack ($data [, insert = { key => val, ... } ] )> Providing the "insert" argument let's you supply additional arguments to the class' "new" function, or override ones from the serialized data. Introspection meta BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. AUTHOR
Chris Prather <chris.prather@iinteractive.com> Stevan Little <stevan.little@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2007-2008 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-02-28 MooseX::Storage::Basic(3pm)
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy