How do you sort filenames:
1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21
as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
instead of:
1
10
11
12
13
14
15
16
17
18
19
2
20
21
3
4
5
6
7
8
9
Thanks,
Kenny.
How do you sort filenames:
1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21
as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
instead of:
1
10
11
12
13
14
15
16
17
18
19
2
20
21
3
4
5
6
7
8
9
Thanks,
Kenny.
ls | sort -n
actually I have a constant word at the beginning of each file name.
example: filename_
ls | sort -n is not working on my list of files.
I still get:
filename_1
filename_10
etc
instead of:
filename_1
filename_2
etc.
NOTE: I am using Unix For Microsoft Windows commands.
Do you have Perl there?
ls | perl -F"\n" -la0ne '$,="\n";print sort {(split /_/,$a)[1]<=>(split /_/,$b)[1]} @F'
ls | nawk -F_ '{print $NF,$0}' | sort -k 1,1n | cut -d ' ' -f2-
You can still make it simpler by:
ls filename* | sort -t'_' -k 2,2n
If you are using gnu ls, check out the "-v" option.