bashsortinginteger

Sorting by integer value


I am writing a bash script and I am using

ps -e -o %cpu

command.

I would like to have output of sorted %cpu values (descending). How to do that? I know that I should use sort command but I don't know how.


Solution

  • ps -e -o %cpu | sort -nr
    

    n for numeric, r for reverse. If you also want to remove the header:

    ps -e -o %cpu | sed '1d' | sort -nr