I am trying to numerically sort a series of files output by the ls command which match the pattern either ABCDE1234A1789.RST.txt
or ABCDE12345A1789.RST.txt
by the '789
' field.
In the example patterns above, ABCDE
is the same for all files, 1234
or 12345
are digits that vary but are always either 4 or 5 digits in length. A1
is the same length for all files, but value can vary so unfortunately it can't be used as a delimiter. Everything after the first .
is the same for all files. Something like:
ls -l *.RST.txt | sort -k +9.13 | awk '{print $9} ' > file-list.txt
will match the shorter filenames but not the longer ones because of the variable length of characters before the field I want to sort by.
Is there a way to accomplish sorting all files without first padding the shorter-length files to make them all the same length?