Hi,
I'm on a Java project and we've found ourselves needing the beautiful language of AWK!
Problem:
I am reading through a file, line-by-line which looks like this:
---------------------------
[dataA1] {dataA2}
[dataB1] {dataB2}
[dataC1] (dataC2}
garbageG1
garbageG2
[dataD1] {dataD2}
---------------------------
If the first character of field 1 is a "[", then make a file which must be named using the value in field 2. This new file must contain the the line from the file being currently looked at.
Else, the line is garbage, so: it needs to be added to the previous newly made file. When adding this line of garbage it must be prefixed with field 1 and field 2 that the newly made file was populated with.
So the results would be:
A file called "dataA2" which has 1 line which is:
"[dataA1] {dataA2}".
A file called "dataB2" which has 1 line which is:
"[dataB1] {dataB2}".
A file called "dataC2" which has 3 lines which are:
"[dataC1] {dataC2}
[dataC1] {dataC2} garbageG1
[dataC1] {dataC2} garbageG2".
A file called "dataD2" which has 1 line which is:
"[dataD1] {dataD2}".
wow !
Any help would be great. I've got bits and pieces myself but i cant put it together.
Steve
I'm on a Java project and we've found ourselves needing the beautiful language of AWK!
Problem:
I am reading through a file, line-by-line which looks like this:
---------------------------
[dataA1] {dataA2}
[dataB1] {dataB2}
[dataC1] (dataC2}
garbageG1
garbageG2
[dataD1] {dataD2}
---------------------------
If the first character of field 1 is a "[", then make a file which must be named using the value in field 2. This new file must contain the the line from the file being currently looked at.
Else, the line is garbage, so: it needs to be added to the previous newly made file. When adding this line of garbage it must be prefixed with field 1 and field 2 that the newly made file was populated with.
So the results would be:
A file called "dataA2" which has 1 line which is:
"[dataA1] {dataA2}".
A file called "dataB2" which has 1 line which is:
"[dataB1] {dataB2}".
A file called "dataC2" which has 3 lines which are:
"[dataC1] {dataC2}
[dataC1] {dataC2} garbageG1
[dataC1] {dataC2} garbageG2".
A file called "dataD2" which has 1 line which is:
"[dataD1] {dataD2}".
wow !
Any help would be great. I've got bits and pieces myself but i cant put it together.
Steve