It can all be done with a single awk. It just would have been helpful to know that the continuation lines were indented. In the future, if you place "code tags" around programmes or output, it preserves spacing and can illustrate things like the multiple blanks. To insert code tags, click on the '#' button at the top of the edit window and then type/paste your text between the tags that are inserted in the window.
Here is a revision to the awk that will allow for multiple spaces at the beginning of a continued line. It assumes that the text is aligned below the numbers like this:
leading junk tokens on first line [01.00 02.00 03.00 04.00 05.00 06.00 07.00 08.00 09.00 10.00 11.00 12.00 13.00
14.00 15.00 16.00 17.00 18.00 19.00 20.00 21.00 22.00 23.00 24.00 25.00 26.00
27.00 28.00 29.00 30.00 31.00 32.00 33.00 34.00 35.00 36.00 37.00 38.00 39.00]
The programme will properly handle the case where the blanks in the data are at the beginning of a continued record -- it does not blindly delete all blanks at the beginning of the line to provide for this.
awk '
BEGIN {printf( "[" ); } # opening bracket
/]/ {
if( last )
printf( "%s\n", last ); # print the last one we saw
if( partial ) # add current line to partial buffer
buffer = partial " " substr( $0, indent ); # ditch leading spaces, but dont trash the "blank == 0"
else
buffer = $0; # no partial, just use current line
gsub( ".*\\[", "[", buffer ); # trash all before [, but keep [
gsub( "].*", "]", buffer ); # trash all after ], but keep ]
gsub( "\\[", "", buffer ); # ditch opening bracket
gsub( "]", "", buffer ); # ditch trailing bracket
gsub( " +", " 0.00 ", buffer ); # two or more spaces causes 0.00 to insert
gsub( " ", " ", buffer ); # cleanup if multiple spaces
gsub( " $", "", buffer ); # cleanup trailing space if there
gsub( "^ ", "", buffer ); # cleanup leading space if there
last = buffer; # save to add trailing ] if this is the last one
join = 0;
partial = "";
next;
}
/\[/ { # beginning of matrix, but not end
indent = index( $0, "[" ) + 1; # number of spaces to skip for secondary lines
gsub( "^.*\\[", "[", $0 ); # ditch beginning junk
partial = $0; # start a partial buffer
join = 1; # join next line(s) if not end of matrix
next;
}
join == 1 {
buffer = substr( $0, indent ) # ditch leading spaces, but dont trash the "blank == 0"
partial = partial " " buffer; # add this line to the partial matrix
next;
}
END {
printf( "%s]\n", last );
}
' $f
Hope this works better for you.