4 ms·
Sorting so "foo9" is before "foo10" is called natural sort. I found out about natural sort a week ago and I am thrilled that my programs now print their output
by kens 1y ago
Sorting so "foo9" is before "foo10" is called natural sort. I found out about natural sort a week ago and I am thrilled that my programs now print their output in a sensible order. Give natural sort a try and see if it improves your life too :-)
I found the magic two lines of Python to do a natural sort here, by the way: https://stackoverflow.com/questions/11150239/natural-sorting/11150413#11150413 https://stackoverflow.com/questions/11150239/natural-sorting...
- jcynix 1y agoNatural sort is an Option in sort(1): for i in $(seq 2 10) ; do touch img_$i-hn.txt done ls img_* | sort -V img_2-hn.txt img_3-hn.txt img_4-hn.txt img_5-hn.txt img_6-hn.txt img_7-hn.txt img_8-hn.txt img_9-hn.txt img_10-hn.txt And we have "sort -h" to sort the output of e.g. "du -sh *" properly. Edit: formatting and add sort -h