Skip to content
Advertisement

Sorting of data in descending order

Allow me to clarify my query:

I have a database with thousand of character strings, followed by some values (based on scoring matrix)

    GKCHGYEGRGFQGRHYEGRSDGPNGQL  25
    WGCGGYESRGFQGRHYEGGGDCPNGQG  56
    GLCCGYEGRGFQCRHYEGGGDGPNDQL  43
    GKGCGYEGRGFQGRHYEHGIDKDHFFR  24
    PYGSGGNRARRSGCSWMLYEQVNYSGD   4
    DFTEDLRCLQDVFAFNEIVSLNVLERL   3
    REDYRRQSIYELSNYRCRQYLTDPSDY  18

There are equal values also present. I am trying to sort the data in descending order using:

    sort -n -r file.txt

But the data is still disarranged. Also tried by adding -k argument.

Is it possible that i could get the following result:

   GKCHGYEGRGFQGRHYEGRSDGPNGQL  56
   WGCGGYESRGFQGRHYEGGGDCPNGQG  56
   GLCCGYEGRGFQCRHYEGGGDGPNDQL  56
   GKGCGYEGRGFQGRHYEHGIDKDHFFR  43
   PYGSGGNRARRSGCSWMLYEQVNYSGD  25
   DFTEDLRCLQDVFAFNEIVSLNVLERL  25
   REDYRRQSIYELSNYRCRQYLTDPSDY  24

and so on.

I am new to Linux. Any help will be appreciated.

Advertisement

Answer

sort -k 2 -nr

This will number sort 2nd field in reverse order and print

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement