Given an ls -l
list of directories which are software release versions, how to sort into human-preferable form? Eg:
$ ls -loghF total 209 drwxr-xr-x 2 3 Jun 18 11:33 12.0.40.0/ drwxr-xr-x 2 3 Aug 24 14:45 13.0.11.10/ drwxr-xr-x 2 3 Jul 13 14:12 13.0.11.4/ drwxr-xr-x 2 3 Jul 26 15:30 13.0.11.5/ drwxr-xr-x 2 4 Jul 27 11:33 13.0.11.6/ drwxr-xr-x 2 3 Aug 3 11:41 13.0.11.7/ drwxr-xr-x 2 3 Aug 10 11:53 13.0.11.8/ drwxr-xr-x 2 3 Aug 17 17:00 13.0.11.9/ drwxr-xr-x 2 3 Aug 3 14:37 13.0.17.0/ drwxr-xr-x 2 3 Aug 13 11:50 13.0.18.0/ drwxr-xr-x 2 3 Aug 17 11:21 13.0.19.0/ drwxr-xr-x 2 3 Jul 28 15:00 13.0.9.1/
The desired result is:
$ ls -loghF | sort ... total 209 drwxr-xr-x 2 3 Jun 18 11:33 12.0.40.0/ drwxr-xr-x 2 3 Jul 28 15:00 13.0.9.1/ drwxr-xr-x 2 3 Jul 13 14:12 13.0.11.4/ drwxr-xr-x 2 3 Jul 26 15:30 13.0.11.5/ drwxr-xr-x 2 4 Jul 27 11:33 13.0.11.6/ drwxr-xr-x 2 3 Aug 3 11:41 13.0.11.7/ drwxr-xr-x 2 3 Aug 10 11:53 13.0.11.8/ drwxr-xr-x 2 3 Aug 17 17:00 13.0.11.9/ drwxr-xr-x 2 3 Aug 24 14:45 13.0.11.10/ drwxr-xr-x 2 3 Aug 3 14:37 13.0.17.0/ drwxr-xr-x 2 3 Aug 13 11:50 13.0.18.0/ drwxr-xr-x 2 3 Aug 17 11:21 13.0.19.0/
The sort must skip past the date portion of each line, then sort numerically (eg, starting with the 12 or 13), using '.' as a field separator.
I thought of two approaches, but am having difficulty with the sort -k syntax, if it's supported at all:
(1) Skip the first 36 characters, then with '.' as field separator, sort numerically on the next 4 fields.
(2) With field separator as whitespace, skip to the 7th field, then change the field separator to '.' and sort numerically on the next 4 fields.
The alternate is a little Perl script, but can't Unix sort do this "simple" task?