BSD does not provide -V by default, so Ben's solution is as close as possible. For your convenience, I post here our version, which is able to sort files of the type <label>-<version>.<ext> :
% ls bla-*.ime | sed -Ee 's/^(.*-)([0-9.]+)(\.ime)$/\2.-1 \1\2\3/' | sort -t. -n -k1,1 -k2,2 -k3,3 -k4,4 | cut -d\ -f2- bla-1.ime bla-1.0.ime bla-1.0.0.ime bla-1.1.ime bla-1.1.29.ime bla-1.2.3.ime bla-1.2.29.ime bla-1.2.30.ime bla-1.3.ime bla-1.3.0.ime bla-1.3.1.ime bla-1.3.10.ime bla-1.3.20.ime bla-1.7.ime bla-1.11.29.ime bla-2.3.2.ime bla-11.2.2.ime
Brief explanation:
- List the files you want to sort with
ls . - Find the version number and line prefix.
- In this case, add
-1 to the end to first make the sorting of the shorter version (up to .0 even). You can change -1 to 0 if you think 1.3 equivalent to 1.3.0 . - Sort the strings using the proposed Ben solution by version number.
- Disable version prefix from string.
The list now contains a list of file names sorted by list. Any additional sorting in the label part remains as an exercise for the reader.
Coroos Jun 02 '14 at 11:28 2014-06-02 11:28
source share