Skip to main content
1 of 3
John1024
  • 76.4k
  • 12
  • 176
  • 165

Since this is posted this on unix.stackexchange.com, I am going to assume that you have access to the usual unix tools.

Alphabetic sorting on first column:

$ sort file.txt >alpha_sorted.txt $ cat alpha_sorted.txt d 29 d 5 d 9 f 2 f 2 g 1 g 10 g 5 h 1 s 4 s 5 

Numeric sorting:

$ sort -nk2 file.txt >numbers_sorted.txt $ cat numbers_sorted.txt g 1 h 1 f 2 f 2 s 4 d 5 g 5 s 5 d 9 g 10 d 29 

-n specifies numeric sorting. -k2 specifies sorting on the second column.

For more information, see man sort.

John1024
  • 76.4k
  • 12
  • 176
  • 165