Cut and paste data in matrix form

I have large formatted data file with five columns. This has to be rearranged in lower order matrix form as shown below for sample data.

1 2 3 4 5
1.0
3.0 2.0
5.0 3.0 2.0
4.0 3.0 1.0 6.0
2.0 3.0 4.0 5.0 1.0
1.0 4.0 2.0 3.0 5.0
3.0 5.0 4.0 2.0 8.0
1.0 3.0 2.0 4.0 5.0
2.0 1.0 3.0 7.0 8.0
6 7 8 9
1.0
3.0 5.0
1.0 3.0 2.0
2.0 3.0 4.0 5.0

1 2 3 4 5 6 7 8 9
1.0
3.0 2.0
5.0 3.0 2.0
4.0 3.0 1.0 6.0
2.0 3.0 4.0 5.0 1.0
1.0 4.0 2.0 3.0 5.0 1.0
3.0 5.0 4.0 2.0 8.0 3.0 5.0
1.0 3.0 2.0 4.0 5.0 1.0 3.0 2.0
2.0 1.0 3.0 7.0 8.0 2.0 3.0 4.0 5.0

Thanks in advance,
Dhilip

hello ,

Is this homework?

No. This is not homework! Thanks.

hello,

I would like to try to do it . seems like a great sudoku puzzle to me. but only I would like to know first that what kind of work involves this kind of number arrangements.

Cheers,
gaurav.

Hello Gaurav,

I am extracting data from the results of quantum chemical calculations. Using grep and awk commands, I have printed the necessary data from the very large output in a new file. But the data is in five column format and I need this rearranged in a lower order matrix form. The matrix data becomes input for another fortran code for further calculation! The data shown above is only an example data. Hope this helps.

Many thanks.
Dhilip

I try to understand your request. But it makes me confused.

In your sample file, there are not 5 columns every line. So what's your desired output?

The last set varies between column 1 to 5. In the sample data, the last set has 4 columns (6 7 8 9).

For example, my input dat file has:

c1 c2 c3 c4 c5
.
.
c6 c7 c8 c9
.
.

And desired ouput is:

c1 c2 c3 c4 c5 c6 c7 c8 c9
.
.
.
.

Thanks.

More clear now. But when there is a 5-columns line, what's the rule to attach with other line?

For example, when you see the first line is 5-columns, why attach 6 7 8 9, not 1.0 which is next the line?