Monday, July 24, 2017

TIL: Sort human friendly values

Sorting numeric values in the input is easy. It just takes "sort -n". But what if the input contains human friendly units. For intance, "5G", "3M", "4K", etc. There is a flag to recognize and sort based on the human friendly units: "-h".

Incorrect: du -h | sort -nr
Correct: du -h | sort -rh

Caveat: "sort -h" works only on upper-case units. "K" will be treated as kilos, but "k" will not be!

No comments: