I have a text file that looks something like this:
A21 103 A22 103 A23 103 A25 103 A26 103 A27 103 12.3 7.3 .0289 179 2 5 1 4 3 1 + 0 0 0 A28 103 4.5 4.2 .0000 479 1 0 0 0 0 0 + 0 0 0 10.2 9.6 .0188 250 2 5 0 4 2 3 + 0 0 0 10.2 9.6 .0188 250 2 5 0 4 2 3 + 0 0 0 A29 103 4.5 4.2 .0000 479 1 0 0 0 0 0 + 0 0 0 10.2 9.6 .0188 250 2 5 0 4 2 3 + 0 0 0 A30 103 A32 103 4.5 4.2 .0000 479 1 0 0 0 0 0 + 0 0 0 10.2 9.6 .0188 250 2 5 0 4 2 3 + 0 0 0 A33 103 4.5 4.2 .0000 479 1 0 0 0 0 0 + 0 0 0 10.2 9.6 .0188 250 2 5 0 4 2 3 + 0 0 0 A34 103 A36 103 4.5 4.2 .0000 479 1 0 0 0 0 0 + 0 0 0
The data is separated by tabs or spaces
I wish to be able to read in the file, remove the lines with two batches of text(eg.'A21 103') unless they are followed by a longer line of data(eg.'12.3 7.3 .0289'...).
If they are followed by a longer line of data, to read the two batches of text and insert them at the beginning of the subsequent longer lines until the next short batch is found. And so on through the file.
In this example, I want the output therefore to look like this:
A27 103 12.3 7.3 .0289 179 2 5 1 4 3 + 1 0 0 0 A28 103 4.5 4.2 .0000 479 1 0 0 0 0 + 0 0 0 0 A28 103 10.2 9.6 .0188 250 2 5 0 4 2 + 3 0 0 0 A28 103 10.2 9.6 .0188 250 2 5 0 4 2 + 3 0 0 0 A29 103 4.5 4.2 .0000 479 1 0 0 0 0 + 0 0 0 0 A29 103 10.2 9.6 .0188 250 2 5 0 4 2 + 3 0 0 0 A32 103 4.5 4.2 .0000 479 1 0 0 0 0 + 0 0 0 0 A32 103 10.2 9.6 .0188 250 2 5 0 4 2 + 3 0 0 0 A33 103 4.5 4.2 .0000 479 1 0 0 0 0 + 0 0 0 0 A33 103 10.2 9.6 .0188 250 2 5 0 4 2 + 3 0 0 0 A36 103 4.5 4.2 .0000 479 1 0 0 0 0 + 0 0 0 0
The data lines may be in batches of one, two, three, four or even five lines before the short line which is actually a kind of a heading for the data that follows below it.
(The 'headings' without 'data' below them are not required and need to be dropped from the output, as stated above.)
I cannot find a way to do this.
I have googled a lot for examples but without any success. Hope someone can teach me how to do this.
Thank you very much for your help.
In reply to Insert Text which is Read from the Line Above by jlb333333
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |