Suppose a text file contains x the number of columns in a row.
$cat file
Is there a way in bash to sort these columns by the number of text strings (i.e. filled lines) that they contain, keeping the internal order of the rows in each column?
$sought_command file foo foo foo bar bar bar baz baz qux
Essentially, the column with the largest number of rows should be the first, the column with the second number of rows should be the second, etc.
(This task will be easily implemented using R
, but I'm interested in learning about the solution through bash.)
EDIT 1 :
Below are some additional information. Each column contains at least one text row (that is, one filled row). Text strings can be any alphanumeric combination and have any length (but obviously do not contain spaces). Output columns must not contain empty rows. There is no a priori restriction for a column delimiter if it remains consistent across the table.
All that is needed for this task is moving the columns as they are sorted by the length of the column. (I know that implementing this in bash sounds easier than it really is.)
source share