I think 'sort -h' does just that, though for your input you'll need to remove
the spaces between the numeric part and the units.
Eg:
$ ( tr -d ' ' | sort -h ) << EOF
100.0 Kb
303 Mb
4.01 Gb
20 Mb
EOF
100.0Kb
20Mb
303Mb
4.01Gb
Works great with, eg, 'du -sh * | sort -h'
Carl
On Mon, 20 Sep 2021, mm1miq.d@gmail.com wrote:
Hello,
The SORT command in GNU coreutils does not have a sort by DATA SIZE
parameter.
for example, to sort:-
-----------
100.0 Kb
303 Mb
4.01 Gb
20 Mb
-----------
sorts output will be:-
-----------
303 Mb
100.0 Kb
20 Mb
4.01 Gb
-----------
It would be nice if thier was a parameter that sorted by size so the
output
would be 100.0 Kb, 20 Mb, 303 Mb, 4.01 Gb
Would be great if such a parameter was added.
Regards.