GNU sort file names with prefix and one or two digit

0

I would like to use GNU sort to have the file names from a find command sorted by the numbers in the name. The name of the file is "cycle" then the first number to sort by, then ".subset", then the second number to sort by, then "." then the third number to sort by. A simple sort does not work, since the first number can one one or more digits:

find /tmp/folder/ -name "cycle*"  | sort
/tmp/folder/cycle10.subset1.2
/tmp/folder/cycle11.subset1.2
/tmp/folder/cycle12.subset1.2
/tmp/folder/cycle1.subset1.2
/tmp/folder/cycle2.subset1.2
/tmp/folder/cycle3.subset1.2
/tmp/folder/cycle4.subset1.2
/tmp/folder/cycle5.subset1.2
/tmp/folder/cycle6.subset1.2
/tmp/folder/cycle7.subset1.2
/tmp/folder/cycle8.subset1.2
/tmp/folder/cycle9.subset1.2
[...]

Any ideas?

719016

Posted 2014-12-29T13:59:27.797

Reputation: 2 899

Answers

1

... | sort --debug -n -t/ -k4.6

--debug will tell you what sort considers for the comparison while doing its job.
Remove it for the actual use.

sort --help lists the available options, man sort might tell more.

Hannu

Posted 2014-12-29T13:59:27.797

Reputation: 4 950

0

Any character can be the field separator:

-t, --field-separator=SEP
use SEP instead of non-blank to blank transition

... | sort --debug -n -ty -k2.4
... | sort --debug -n -tl -k3.2
... | sort --debug -n -te -k3.1

broomdodger

Posted 2014-12-29T13:59:27.797

Reputation: 1 810