Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    Might want to use tr -s to handle multiple spaces, especially when encountering indentation. Commented May 21, 2012 at 0:02
  • @Arcege: Good point. Although it wont change the result it may fasten script a little bit. Commented May 21, 2012 at 7:10
  • -g (--general-numeric-sort) option of sort may be preferable in some cases. E.g. sort -n will keep 10\n1 4 as is, treating 1 4 as 14, while sort -g will treat it correctly as 1 4\n10. Commented Sep 6, 2015 at 12:04
  • nice command, really deserve a vote up :) Commented Nov 4, 2015 at 13:07
  • 1
    @seler I think you can make the grep and tr part even simpler like below: echo "Lorem ipsum dolor sit sit amet et cetera." | tr ' ' '\n' | grep -v "^$" | sort | uniq -c | sort -bnr Note that I am a beginner, so I may be wrong, please feel free to advise. Commented Oct 26, 2019 at 19:10