Sorting a list

n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run7.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run7.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run6.cmd

I want to sort to look like below:

First sort by field 6, then by field 5, then in increasing numbers of run tags.

n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run6.cmd
 
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run6.cmd
  
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run7.cmd
  
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run6.cmd
n02-z30-dsr65-terr0.50-dc0.008-16x12drw-run7.cmd
  
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.010-16x12drw-run6.cmd

Maybe I'm a bit blind with the input, but could I suggest that the following sort of logic is required.

sort +0.27 -0.29 +0.42 -0.43

I might not have counted correctly, but the sort command say to sort with the first key skipping zero fields, 27 characters ending at zero fields 29 characters then second key as skipping zero fields 42 characters ending at zero fields 43 characters.

It seems to work, but I can't see where your other sort key you are interested is meant to be.

I hope that this helps
Robin
Liverpool/Blackburn
UK

Sticking to exact locations will be a problem as I might have files like

n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.002-16x12drw-run6.cmd
 n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run5.cmd
n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run6.cmd

I want to have a list such that for any given drw tag (e.g. 16x12drw), I have
same value for dc (e.g. dc0.004), and then I have the run tag in increasing numbers.

For example

n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run1.cmd
 n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run2.cmd
 n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run3.cmd
 n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run4.cmd
 

are grouped together, where the only difference in the value of the run.
I want the run value be in increasing values where all the rest of the file name is identical.

Each set of file names will then be ordered in increasing order of the dc values

Example

n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run4.cmd
   

Um ?

Suppose I have the following files in any order,
I want top create an output which looks like the one below

n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run4.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run5.cmd
 
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-8x6drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.5-8x6drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-16x12drw-run4.cmd
  
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.7-16x12drw-run4.cmd

First in increasing values of the drw, example

first the one with 4x3drw, the those with 8x6drw, finally with 16x12drw

For the set of files having 4x3drw, I list the files in the following order

The value of the run should increase having the rest of the file name identical

Example

n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run1.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run2.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run3.cmd
n02-z30-dsr65-terr0.50-dc0.2-4x3drw-run4.cmd

As you can see, the only difference on this set of files is that they are ordered
in the order

run1
run2
run3
run4
sed 's/\.\([0-9][0-9]*\)-/ . \1 - /2' yourfile | sort -k 3n | sed 's/ \([.-]\) /\1/g'

I will complicate it a little more, so files are sorted according to increasing values of the tags

For the drw tag (e.g for 4x3drw, 8x6drw, and, 16x12drw) , I multiply the two numbers. For example 43=12, 86=48, and 16*12=192. Thus I first sort using 4x3drw, then 8x6drw, and finally by 16x12drw. Then for all files having 4x3drw, I look at the value in the dc tag. Example dc0.1 files will be grouped before ones with dc0.8.

Basically it is a bit more structured than the current solution.

More reliable than the one of my previous post
The idea is to isolate every numeric string with one space before and one space after so that we can then perform numeric sorting on the wanted keys(here : 14 & 20)

sed 's/\([0-9][0-9]*\)/ & /g' yourfile | sort -k 14n -k 20n | sed 's/ //g'

Is the above a simplification on your previous command?

---------- Post updated at 01:50 PM ---------- Previous update was at 01:47 PM ----------

If I have a file name such as the one below, how can I get the number associated with the dc tag to get 0.006, or any tag type I want for that matter.

n02-z30-dsr65-terr0.50-dc0.006-16x12drw-run6.cmd

If you add for example a line like :

n02-z30-dsr65-terr0.50-dc0.004-16x12drw-run10.cmd

in the middle of your example file...

You will see that my second command sort it correctly whereas my first proposal doesn't handle it correclty since it was only performing a numeric sorting on the '00n' field and not on the 'X' of the run'X' field which was therefore sorted as litteral instead of numeric so that "10" arrive before 6 (start with 1 and 1<6) but with the second solution, the numeric sorting also apply to the X of runX so 10 is not considered as the string 1+0 but as the number 10 so that 10>6 so the 6 will be displayed before the 10.

Interesting idea using

sed 's/\([0-9][0-9]*\)/ & /g'

The only thing is that it introduces the problem that

n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 010 - 16 x 12 drw-run 1 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 008 - 16 x 12 drw-run 1 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 006 - 16 x 12 drw-run 1 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 004 - 16 x 12 drw-run 1 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 3 . 002 - 16 x 12 drw-run 1 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 006 - 16 x 12 drw-run 2 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 008 - 16 x 12 drw-run 2 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 1 . 010 - 16 x 12 drw-run 2 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 2 . 004 - 16 x 12 drw-run 2 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 002 - 16 x 12 drw-run 2 .cmd
n 02 -z 30 -dsr 65 -terr 0 . 50 -dc 0 . 008 - 16 x 12 drw-run 3 .cmd

it will have problem with sorting for values of the dc as the digit number will not be checked.

just add the corresponding -k Xn sorting

sed 's/\([0-9][0-9]*\)/ & /g' mytst | sort -k 12n -k 14n -k 20n | sed 's/ //g'

I understand now. Thank you for the explanation.

---------- Post updated at 02:11 PM ---------- Previous update was at 02:08 PM ----------

Something like the one below then:

sed 's/\([0-9][0-9]*\)/ & /g' myfile | sort -k 12n -k 14n -k 20n | sed 's/ //g'

... i meanwhile updated my previous post, depending on your requirement, maybe it can be a solution