I am not seeing any relationship between the sample data, the desired output, or sample.txt included in the 1st message in this thread and the shell script shown in the 3rd message in this thread.
I was expecting the sample data shown in the 1st message and the data in sample.txt attached to the 1st message to be the same (or at least similar), but they aren't. I don't see any obvious relationship between the desired output and the sample input or sample.txt data.
Please give us an English description of what the format is for the input data. Then explain why the count shown in the first line does not exactly match the number of characters in the following lines, why some groups start with ength-<number>] while others start with Length-<number>], what determines what should be printed in the 1st two fields of the output, and what determines how much of the text from the input should be copied into the 3rd field in the output.