How can I sort filenames like this
B-100.txt
B-11.txt
A-03.txt
A-01.txt
C-110.txt
C-10.txt
into this?
B-11.txt
B-100.txt
A-01.txt
A-03.txt
C-10.txt
C-110.txt
I'd like to leave the prefix order --B, A, and then C, not ABC-- as is but sort the numbers at the end numerically not alphabetically. The numbers go like
01, 02, ....10, 11, ....100, 101, ...
There's always one hyphen in each filename and it delimits the prefix part and the number part.
I'd like to sort the filenames of files that I export from some software and the software automatically adds this kind of peculiar serial numbers at the end so I'm in trouble generating a sorted list of those filenames. I can't rename those files before sorting.
$ for prefix in B A C; do ls -1 ${prefix}* | sort -V ; donedo what you want for your actual use-case? It seems to work for the sample set you have provided.ls * | sort -Vwill keep prefix-grouping. Also, the-1in my earlier comment is not needed as a non-interactivelshas the output-1implies in an interactive terminal.