Read text-file with words and their occurrence count & print output sorted

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












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







share|improve this question
















  • 4




    Have you looked at man sort?
    – DopeGhoti
    Nov 28 '17 at 19:42














up vote
-1
down vote

favorite












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







share|improve this question
















  • 4




    Have you looked at man sort?
    – DopeGhoti
    Nov 28 '17 at 19:42












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











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







share|improve this question












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









share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '17 at 19:39









Mees van Z

11




11







  • 4




    Have you looked at man sort?
    – DopeGhoti
    Nov 28 '17 at 19:42












  • 4




    Have you looked at man sort?
    – DopeGhoti
    Nov 28 '17 at 19:42







4




4




Have you looked at man sort?
– DopeGhoti
Nov 28 '17 at 19:42




Have you looked at man sort?
– DopeGhoti
Nov 28 '17 at 19:42










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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





share|improve this answer






















  • 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







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407573%2fread-text-file-with-words-and-their-occurrence-count-print-output-sorted%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










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





share|improve this answer






















  • 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














up vote
3
down vote



accepted










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





share|improve this answer






















  • 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












up vote
3
down vote



accepted







up vote
3
down vote



accepted






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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '17 at 21:27

























answered Nov 28 '17 at 19:45









Timothy Martin

4,9542129




4,9542129











  • 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
















  • 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















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




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




1




Consider sort -k3rn
– Jeff Schaller
Nov 28 '17 at 19:58




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




(-g being specific to GNU sort)
– Jeff Schaller
Nov 28 '17 at 20:11

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407573%2fread-text-file-with-words-and-their-occurrence-count-print-output-sorted%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay