1

I have a file and I want it alphabetically sorted:

cat file
peptide9
peptide89
peptide99
peptide79
peptide4
peptide58
peptide990

and when I use

cat file | sort -n

the result is:

peptide4
peptide58
peptide79
peptide89
peptide9
peptide99
peptide990

I tried different options of sort, but the result is always the same!
The output I want is

peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990
fredtantini
  • 15,966
  • 8
  • 49
  • 55

2 Answers2

7

You can use the --version-sort (-V):

$> sort --version-sort t
peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990

An alternative would be, "use 'e' as delimiter, sort the 3 column as number":

$> sort -te -k3 -n t
peptide4
peptide9
peptide58
peptide79
peptide89
peptide99
peptide990
fredtantini
  • 15,966
  • 8
  • 49
  • 55
3

Sort numerically, with the key starting at the 8th character of the 1st field:

sort -n -k1.8 file

Sort with that key, treating it as a number, but not other fields (useful if you have other fields):

sort -k1.8n file

info sort for more details.

Tom Zych
  • 13,329
  • 9
  • 36
  • 53