Reputation: 5488
How do I sort based on the filename numerical value? (using OSX)
1 file_1.txt
7 file_3.txt
1 file_111.txt
11 file_7.txt
14 file_15.txt
54 file_10.txt
54 file_20.txt
Desired output:
1 file_1.txt
7 file_3.txt
11 file_7.txt
54 file_10.txt
14 file_15.txt
54 file_20.txt
1 file_111.txt
I tried sort -k 2,2 but it gives:
1 file_1.txt
54 file_10.txt
1 file_111.txt
14 file_15.txt
54 file_20.txt
7 file_3.txt
11 file_7.txt
Upvotes: 0
Views: 32
Reputation: 324
You need to use "--version-sort" switch of sort:
sort -V -k 2,2
Upvotes: 3