nipy
nipy

Reputation: 5488

Sort on column and numerical value

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

Answers (1)

vonschlager
vonschlager

Reputation: 324

You need to use "--version-sort" switch of sort:

sort -V -k 2,2

Upvotes: 3

Related Questions