Operating System - HP-UX
1832690 Members
2849 Online
110043 Solutions
New Discussion

Re: How to read a data file

 
Abdullatif M. Abdulla
Frequent Advisor

How to read a data file

What is the suitable tool for reading a binary data file?

Urgent help please
15 REPLIES 15
MarkSyder
Honored Contributor

Re: How to read a data file

strings filename|pg

Pipe to more if you prefer.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

I have used strings and od commands but still not getting the required results....
Stephen Keane
Honored Contributor

Re: How to read a data file

You can also try xd (if you want hex output) or 'xd -c' if you want it 'interpreted' into ASCII.
Fred Ruffet
Honored Contributor

Re: How to read a data file

It depends on what you want... If you want an exact output of what's inside, od is the tool. If you want an interpretation of its content, you will need the appropriate app (maybe the one which generate the file).

What program did generate this file ?

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

using the command "file myfile" it shows data

using the command more mydile the result is

M-4M-^AM-GM-^

Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

Its a data file comming from switch using ftp

Yes... I need to read the raw data
Fred Ruffet
Honored Contributor

Re: How to read a data file

So you should use od.
"od -cx file" outputs your file, combining hexa and ascii output.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

When used the od command i got the following result which i am require.
0000000 264 201 307 200 001 022 203 \b d @ # 021 2 005 t 371
b481 c780 112 8308 6440 2311 3205 74f9
0000020 245 006 200 004 254 026 002 3 206 001 \0 207 001 001 210 002
a506 8004 ac16 233 8601 87 101 8802
0000040 I 211 002 \0 \a 212 005 \0 320 V a N 253 006 200
2049 8902 7 8a05 d0 5661 4eab 680


But the format I want is :-
Raw Data:
0 H' A081EA80 01128101 00820100 83086400 27080900
20 H' 20308408 64002708 09000000 A5068004 0A6E0703
40 H' 86010087 01018802 25218902 000B8A02 00CBAB06
60 H' 80040A6E 070E8C0D 48554157 45492E43 4F4D2E43


Any help?
A. Clay Stephenson
Acclaimed Contributor

Re: How to read a data file

This is probably about as close as you are going to get with od:

od -A x -t x1 -v infile > outfile

Another very good tool available for download from any of HP-UX Porting Centre's is "hexedit". It will display the data quite well and if you like you can modify as well.
If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: How to read a data file

SMOP:

---- dump.pl ----

$file = shift @ARGV or die "Please provide file to split and # chunks";
open (FILE, "<$file") or die "Error opening $file";
binmode (FILE);
$offset = 0;
$block = 20;
while ($block == read(FILE, $buffer, $block)){
printf ("%d H'%08X %08X %08X %08X %08X\n", $offset, unpack("L5",$buffer));
$offset += $block;
}

------------ usage -----

$ perl dump.pl dump.pl | head -5
0 H'2466696C 65203D20 73686966 74204041 52475620
20 H'6F722064 69652022 506C6561 73652070 726F7669
40 H'64652066 696C6520 746F2073 706C6974 20616E64
60 H'20232063 68756E6B 73223B0A 6F70656E 20284649
80 H'4C452C20 223C2466 696C6522 29206F72 20646965


----------- note -----
1) Hex dump, DEcimal offsets?
2) Left to right or Right to left?
3) Little-Endian or Big-Endian?
Check out: http://www.perldoc.com/perl5.8.4/pod/func/pack.html


Enjoy!

Hein.


Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

Thanks Hein

Can you make your code more clear I am not a perl programmer:

I excuted the code and getting the following error:-
syntex error in file dump.pl at line 1.next tokens "ARGV myfile"
Excution of dump.pl aborted due to comilation errors.

Thands
Isralyn Manalac_1
Regular Advisor

Re: How to read a data file

The command to use is:

strings

Regards,

Isralyn
Hein van den Heuvel
Honored Contributor

Re: How to read a data file

Hmmm,

Sounds like a cut and paste error.
Maybe a line-wrap? Try again?
You did not re-type did you? Never do that! Only cut & paste. Not for lazyness but for correctness!
Looks like you might have judging by the 'syntex' in your reply. Surely the system said 'syntax' no?

That first line is actually accidently too line (my cut and paste!)

----- put all of this in a file: dump.pl ----
$file = shift @ARGV or die "Provide input file name";
open (FILE, "<$file") or die "Error opening $file";
binmode (FILE);
$offset = 0;
$block = 20;
while ($block == read(FILE, $buffer, $block)){
printf ("%d H'%08X %08X %08X %08X %08X\n", $offset, unpack("L5",$buffer));
$offset += $block;
}
------ end of dump.pl ----

Now provide that file to perl as argument:

perl dump.pl

A little explanation.
- the first line just picks up a first argument and remembers it in variable $file.
- next, try to open that file
- switch to binary mode
- initialize offset and size params.
- read a block, into buffer variable. THis returns the number of bytes read. Processing continutes while that is the same as the number of bytes requests.
- the printf is where the real magic happens in the argument list. We don't give a list of 5 variables as 'usual' but the result from an 'unpack' which is a list of 5 values.
- The unpack argument "L5" tell the system to interpret the 20 bytes read as 5 times a 32-bit integer (see perl online doc!).

Try again!
Hein.


Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

Hi Hein

Thanks for you support

Yes i did cut and paste from begining and i am still getting the error now is:
syntax error in file dump.pl at line 1, next 2 tokens "@ARGV or"
syntax error in file dump.pl at line 2, next 2 tokens ")or"
Excution of dump.pl aborted due to compilation errors.


I am using 10.20 OS.I have attached the binary file


Abdullatif M. Abdulla
Frequent Advisor

Re: How to read a data file

Thanks Hein

It worked fine.....