-1

I have a text file with the following format (retweets and username):

RT @username2    4
RT @Userddssdw   7
RT @usernam54    1
RT @Userddss44   1
RT @usernam1     1
RT @Userddssd1   6

Is there a way of sorting by occurrence and output the result like:

RT @Userddssdw   7
RT @Userddssd1   6
RT @username2    4
RT @usernam54    1
RT @Userddss44   1
RT @usernam1     1

Chris$ somethingIdontKnow | with grep | sort ./textfile.txt

  • 4
    Have you looked at man sort? – DopeGhoti Nov 28 '17 at 19:42
3
sort -r -g -k3 textfile.txt

This will perform a general numeric, reverse sort of the output using the third field. -g is a GNU specific option.

As mentioned by Jeff Schaller, the non-GNU specific option for a numeric sort follows:

sort -r -n -k3 textfile.txt
  • This looks like it. Only when a number of 13 or 18 exist, it will see it as an 1 And lower than 9 I think – Mees van Z Nov 28 '17 at 19:53
  • 1
    Consider sort -k3rn – Jeff Schaller Nov 28 '17 at 19:58
  • (-g being specific to GNU sort) – Jeff Schaller Nov 28 '17 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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