1830581 Members
2915 Online
110015 Solutions
New Discussion

Awk Problem

 
SOLVED
Go to solution
Rodney Hills
Honored Contributor
Solution

Re: Awk Problem

The perl script (must be running perl 5) following when reading the binary data file you posted, will generate the following output.

open(INP,"seek INP,0x118,0; # position past header
while(read(INP,$recsiz,3)) { # get record size
($b1,$rsiz)=unpack("H2 H4",$recsiz);
last if $b1 ne "01";
$rsiz=hex($rsiz);
if (read(INP,$datum,$rsiz)) {
$datum=chr(0) . $recsiz . $datum;
$l=length($datum)-1;
for $i (0..$l) {
$c=substr($datum,$i,1);
printf "%2.2x",ord($c);
print " " if ($i % 2) != 0;
}
print "\n";
}
}


0001 0027 0111 0102 0517 3055 0003 8700 0005 03ff 0201 0202 0901 0a01 0311 9103 308f 0507 0102 0827 9396 56
0001 0027 0111 0102 0517 3055 0000 c900 0002 03ff 0201 0202 0901 0a01 0311 9132 189f 0507 0102 0847 4004 33
0001 0026 0111 0102 0517 3052 0001 4400 0002 03ff 0200 0202 0901 0a01 0311 9184 969f 0506 0102 0821 082f
0001 0027 0111 0102 0517 3055 0006 4600 0009 03ff 0201 0202 0901 0a01 0311 9131 079f 0507 0102 0835 7688 59
0001 0027 0111 0102 0517 3059 0001 dd00 0003 03ff 0201 0202 0901 0a01 0311 9182 030f 0507 0102 0835 2801 51
0001 0027 0111 0102 0517 3100 0000 d100 0002 03ff 0201 0202 0901 0a01 0311 8941 828f 0507 0102 0829 6444 62
0001 0027 0111 0102 0517 3100 0018 9c00 0021 03ff 0201 0202 0901 0a01 0311 9185 703f 0507 0102 0837 0891 26

Note- since the record size is 3 bytes I prepended an extra "00" so the display would line up better.

Note- I see this looks like an ebcdic tape dump. ebcdic tapes have headers based on the block size it was generated with. Be sure you change the "seek" statement with the proper offset to go pass the header data.
The head looks like this-
VOL1JUSTI0CTI128 000001
HDR1FACTURDET 00010001000100 0000201002 000000A0
HDR2V0204802044

Good Luck

-- Rod Hills

There be dragons...
Chris Frangandonis
Regular Advisor

Re: Awk Problem

Hi Ron,

Great stuff. If there was 15 points, you deserve it. Three more question, how can I change "last if $b1 ne "01"; , if there was 02|03|04 in place of 01, and if there are headers in between the records, how can we ignore them so that they could continue to line up. Second senario is that, if we were to read (records)without an extra "00" and without header/hearders , how could it be done.
I have attached two files with both examples as describe above.

Is it possible to write a script in Unix shell as you wrote in perl?

Many Thanks
Chris
Chris Frangandonis
Regular Advisor

Re: Awk Problem

Hi,

Forgot to attach 2nd file.

Thanks
Chris
Rodney Hills
Honored Contributor

Re: Awk Problem

A script would be difficult. The type of parsing you are doing on the data is unique and needs to be at level not handle by standard unix tools.

perl is the best tool for file parsing. I've given you enough to get started, but I think it is up to you now.

This forum structure is a good place for ideas to get started, but at some point the original requester must begin to take ownership of the problem they are trying to resolve.

If you don't have the time to learn the tools that get the job done, then I recommend you hire a consultant who can use the tools to get what you want.

It sounds like the issue is snowballing, and although I can do a quick script to help someone, I don't have time to develop a script that has to handle a various amount of situtations.

If you have a specific question regarding perl or any other unix tool, then post it to the forum and I'm sure you'll get a quick response.

Again, Good Luck

-- Rod Hills
There be dragons...