DubiousAlliance
Technical User
Need some guidance on how to use awk to append the line(s) that match a regexp to the previous unmatched line within a file.
For example, I have a comma delimited file that looks like:
01,123456789,123456789,,1234,1234,,12345
02,12345654321,12345,,,12345,12345
99,00000,00000,000000,,,000
99,11111,11111,1111,,,111,11
10,123456,123456,654321,654321
99,00000,00000,00000,,,00000
11,123456,123456,12345654321,,,000
The first two instances of the lines that begin with "99" need to be appended to the line that begins with "02". The third instance of the line that begins with "99" needs to be appended to line that begins with "10".
I've been playing with the awk command trying to use:
awk '/^99/ { print LINE }; {LINE=$0}' < FILE
...But am having trouble with the multiple instance of the "99" line.
Any help appreciated.
Thanks!
For example, I have a comma delimited file that looks like:
01,123456789,123456789,,1234,1234,,12345
02,12345654321,12345,,,12345,12345
99,00000,00000,000000,,,000
99,11111,11111,1111,,,111,11
10,123456,123456,654321,654321
99,00000,00000,00000,,,00000
11,123456,123456,12345654321,,,000
The first two instances of the lines that begin with "99" need to be appended to the line that begins with "02". The third instance of the line that begins with "99" needs to be appended to line that begins with "10".
I've been playing with the awk command trying to use:
awk '/^99/ { print LINE }; {LINE=$0}' < FILE
...But am having trouble with the multiple instance of the "99" line.
Any help appreciated.
Thanks!