Hmm, this is not a site for providing ready made code for free. This is a site for helping you, provided you show some efforts in doing it yourself.

We can help you correcting existing code, or giving some clues on how to do things, but we are generally not going to make your work for you, nor provide ready-made solutions for homework. Can you please show what code you've written and explain why it does not fit your needs?

In order to get the answer you want, you not only must follow Laurent's suggestions, you must clarify your requirements. I assume that the missing "<" from the second command is a typo. I cannot even guess why you only want two of the three command blocks in your input file.

This input is not easy to parse. I strongly recommend that you start by trying to find a module which can do it. My attempts to use a regex have all failed.

The long records in your input are hard to copy accurately and make your post hard to read. Attach the file rather than pasting it into your post. Good Luck, Bill