Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have the following problem concerning the sorting of a content of a file. I have a file called points.txt and it contains the following table of data:

Jim:4
Tim:8
Lin:6
Tom:1
Esko:2
Jaska:5
Erkki:7 

Now how can I list the following list in numerical order (highest first) or how can I list the three names with highest scores. I have tries the following by they don't seems to work

sort -n -k 1,1 points.txt
sort -n points.txt
sort -n ^: points.txt
share|improve this question
    
Please use meaningful titles, not “meta-titles” like “Question about X”. We know you have a question, you're posting a question. The title should describe what your question is about, it should be the gist of your question. –  Gilles Nov 17 '13 at 20:31
add comment

1 Answer 1

If you looking for the top 3

sort -k2,2rn -t: points.txt  | head -n 3 | cut -f1 -d:

-k specifies the sort field, the parts that follow indicate the following

2,2 - sort key starts and ends at field 2

n - numeric sorting

r - reverse sorting

-t is used to specify the field separator, which in this case is :

share|improve this answer
    
could you explain this part more in details: -k2,2rn -t: –  cash Nov 16 '13 at 17:58
    
@cash, added some details. Try man sort and info sort on your installation for documentation –  1_CR Nov 16 '13 at 18:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.