dHi,
I have the attached file(actual file can be extracted post unzipping it) & i am trying to use the following code for coversion to hex format.
Starting hex value is 84 which is start of the record & termination is done using 00 00 followed by 84(hex) which i can see in the dump clearly using the below command(od) but i want all the records/lines to be arranged accordingly so that further processing can be done.
Hi RudiC,
Trying to write the required output(sequence no & timestamp) from hex converted file(DDI15.09.02.C_HEX) from original binary file(DDI15.09.02.C) attached earlier.
Now from the above hex files i want to fetch data from 9th fields onwards which is covered in function ano(i) in the code below & from 15th onwards for the timestamp which is written in function timestamp. But i am getting the required output via function ano but not from timestamp function which is coming as 0 .
Hope it clears the requirement
I have expanded your zip file and the start bytes are nothing like yours, that helps - not.
So $9, $10, $11, $12 and $13 are BCD AND $15, $16, $17 are HEX values for the year in the file you gave; that is 15\09\03 ; and similarly $18, $19, $20 for the time...
Why did you not tell us that part of the info is BCD and the other part HEX to decimal conversion?
Longhand the second part only for just ONE set of values and added a newline just to make it clear...
The BCD part is easy...
OSX 10.7.5, default bash terminal...
Thanks Wisecracker & RudiC for the help & apologies for the info not shared earlier. Thought that i would be able to do it.
Anyways, can you please suggest some other alternative looking into my requirement? Thanks in advance
Please take way more care when specifiying your request! Some comments:
a) the two lines in your sample file in post#11 don't have the same structure, so anything developed for one line will fail on the other.
b) in your "ano" function you use byte 9 up to 9+6=15, in "timestamp" you use bytes 15+. There's an overlap; byte 15 is used/interpreted/worked upon twice; it's beyond my imagination that this be correct.
c) you didn't spend a second to explain the structure of the file; wisecracker (as well as others like me) did a good job in guessing/determining it but this is certainly part of the specification and not in the role of the coder.
d) the strtonum function is not offered by ALL awk versions, and I think you only need it in very special cases due to awk 's variables' string/number dualism.
---------- Post updated at 20:52 ---------- Previous update was at 18:18 ----------
Howsoever, the main problems in your awk script are the assignments to $str and $s . As neither of those is defined, they evaluate to "" or 0 , and thus the assignments overwrite $0 i.e. the source line worked upon. That's why after the call to "ano", "timestamp" has nothing to read anymore.
Try