Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can awk open a bin file

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi all,

In order for me to complete or ask any questions with my script, I was wondering weather awk
can read a bin file, just like perl can using the "open" cmd and if so how can this be done.

Many Thanks
Chris
 
Hi

[tt]awk[/tt] can read any file. If your problem is reading just a part of the file and there is no separator, your problem seems to be similar to mine, asked in thread271-1114091. The only problem would be, that the solution is [tt]gawk[/tt] specific.

Feherke.
 
Hi Feherke,

Thanks for the reply.

I still dont get it. My file has a header, body and a trailer, size can very from 15K to 4MB ,how would you go about it.

Thanks
Chris
 
Hi Feherke,


My initial question was instead of me using xd or od or dd , can awk read this file without been converted.

Below is an xd dump of the file

0000000 4837 7470 722b 3a30 3964 7331 3753 4654
0000010 3030 3030 6161 6161 6161 6161 6161 6161
0000020 6161 6161 6161 6161 6161 3781 0000 0000
0000030 0123 0108 92aa aa20 2020 2020 2020 2020
0000040 2020 2020 2020 2020 0604 1513 5516 0123
0000050 2621 96aa aaaa aaaa aaaa aaaa aaaa aaaa
0000060 aaaa aa00 0004 2020 2053 5350 0000 26ac
0000070 0000 0037 8100 0000 0001 2301 0892 aaaa
0000080 2020 2020 2020 2020 2020 2020 2020 2020
0000090 2006 0415 1355 4201 2326 2196 aaaa aaaa
00000a0 aaaa aaaa aaaa aaaa aaaa aaaa 0000 0420
00000b0 2020 5353 5000 0026 ac00 0000 5476 7470
00000c0 722b 3a30 3964 7331 3753 4654 3030 3030
00000d0 3030 3032 3030 3030 3030 3030 3030 3030
00000e0 3030 3030 3030 3030 3230 3030 3030 3030
00000f0 3030 3030 3030 3030 3030 3030 3032 3030
0000100 3030 3030 3030 3030 3030 3030 3030 3030
0000110 3030 3230 3030 3030 3030 3030 3030 3030
0000120 3030 3030
0000124

0000000 H 7 t p r + : 0 9 d s 1 7 S F T
0000010 0 0 0 0 a a a a a a a a a a a a
0000020 a a a a a a a a a a 7 81 \0 \0 \0 \0
0000030 01 # 01 \b 92 ª ª
0000040 06 04 15 13 U 16 01 #
0000050 & ! 96 ª ª ª ª ª ª ª ª ª ª ª ª ª
0000060 ª ª ª \0 \0 04 S S P \0 \0 & ¬
0000070 \0 \0 \0 7 81 \0 \0 \0 \0 01 # 01 \b 92 ª ª
0000080
0000090 06 04 15 13 U B 01 # & ! 96 ª ª ª ª
00000a0 ª ª ª ª ª ª ª ª ª ª ª ª \0 \0 04
00000b0 S S P \0 \0 & ¬ \0 \0 \0 0 v t p
00000c0 r + : 0 9 d s 1 7 S F T 0 0 0 0
00000d0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0
00000e0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0
00000f0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0
0000100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0000110 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
0000120 0 0 0 0

1) the first 42bits is the header when converted to ascii is show above
2) The actual record always starts with 3781 or 0037 8100 and converted starts with 7 81|82|83 etc
3) the trailer starts with 5476 and when converted to ascii is show above till the end.

The result for eg : should look something like this
==========================================

H 7 tpr+:09 ds17 SFT 0000
aaaaaaaa aaaaaa aaaa aaaa
7 81 0?????????aaaa 20060421201237 0?????????????aaaa 000143 002184 S 01 00034a5b V J5#1 31
7 81 0?????????aaaa 20060421211133 0?????????aaaaaaaa 000072 003269 S 01 0058595b V B 2 31
T v tpr+:09 ds17 SFT
00000002 0000000000000
00000002 0000000000000
00000002 0000000000000
00000002 0000000000000
0000

How this helps

Thanks
Chris
 
Hi

Abit more clear now. I belive that the problem could be solved with an improved implementation of [tt]awk[/tt], like [tt]gawk[/tt], maybe [tt]nawk[/tt], but I would not try it. [tt]awk[/tt] is too much text oriented.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top