I have a file like this (with hundreds of lines and columns)
1 2 3
4 5 6
7 88 9
and I would like to re-order columns basing on the last line values (or a specific line values)
1 3 2
4 6 5
7 9 88
How can I use awk (or other) to accomplish this task? Thank you in advance for your help
EDIT: I would like to thank everybody and to apologize if I wasn't enough clear. What I would like to do is:
- take a line (for example the last one);
- reorder the columns of the matrix using the sorted values of the chosen line to derermine the order.
So, the last line is 7 88 9
, which sorted is 7 9 88
, then the three columns have to be reordered in a way such that, in this case, the last two columns are swapped.
A four-column more generic example, based on the last line again:
Input:
1 2 3 4
4 5 6 7
7 88.0 9 -3
Output:
4 1 3 2
7 4 6 5
-3 7 9 88.0