A similar question to mine was asked that concerned transposing multiple columns into rows. However, the particular column format that I am dealing with is slightly different in that my file contains a varying number of columns that sometimes have duplicates.
For example:
100
1
2
3
200 300
1 1
2 2
3 3
100
1
2
3
400 500 600 700 800 900
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
100 400 700
1 1 1
2 2 2
3 3 3
I would like to transpose these columns into rows that look like the following:
100 1 2 3
200 1 2 3
300 1 2 3
100 1 2 3
400 1 2 3
500 1 2 3
600 1 2 3
700 1 2 3
800 1 2 3
900 1 2 3
100 1 2 3
400 1 2 3
700 1 2 3
And then sort the rows by the values of the first column as follows:
100 1 2 3
100 1 2 3
100 1 2 3
200 1 2 3
300 1 2 3
400 1 2 3
400 1 2 3
500 1 2 3
600 1 2 3
700 1 2 3
700 1 2 3
800 1 2 3
900 1 2 3
And sum the values for duplicated rows as follows:
100 3 6 9
200 1 2 3
300 1 2 3
400 2 4 6
500 1 2 3
600 1 2 3
700 2 4 6
800 1 2 3
900 1 2 3
You will notice that because rows 100, 400, and 700 had duplicates, their columnar values have been summed.
Any insights or suggestions are greatly appreciated.