I'm looking for a pipeable one-liner to reorder a large number of columns (where manually entering the column numbers in e.g. an awk
command such as awk '{print $3,$2,$1}'
is not feasible). The order could be given by a sorting scheme (alphabetical, numerical – so like 'sort' but acting on columns rather than rows.) or be arbitrarily given in a text file.
Lum – How to reorder a large number of columns
columnssort
Best Answer
Here is a streamable solution.
I assume you want to sort based on the first row of the columns, otherwise adapt to get the sorting key from somewhere else.
Generate sorting key (reusing Rush's array):
$key
now holds:Now use the key to sort columns:
Output: