I have files containing variable length records without linefeeds that I want to convert to a standard linefeed x'0a' terminated file format.
Each "record" begins with a two byte length field followed by two null bytes followed by the record data. There is no LF to indicate the end of each line, just another length field and record data.
Here is an example of the first three lines of a file in hex format. I've separated the four byte record length descriptor from the record data for clarity, but in the file, there are no terminating linefeeds, and all the data is a single stream. 1200 in the first two bytes of the first record indicate a length of 18 (decimal) bytes. 0900 in the second record indicates 9 bytes of data. 1700 in the third indicate 23 bytes of data.
In reality, it looks like this in the file:
You can see that the length in the record descriptor doesn't include the length of the descriptor, just the data that follows.
So what I'd like to do is read the file, copy only the data bytes that follow each length field for the indicated number of bytes, then add a linefeed character x'0A', write that to an output file, and continue with the next record until the end of the file.
In this example, I'd expect to end up with the following (hex format):
Note that the four byte record length descriptor fields are gone, and each line is terminated with a linefeed character.
Is it possible to do accomplish this in a bash script? I'm not really looking for a working script, just an idea of some commands or techniques to get me started in the right direction.