I didn't know that you could use the shell like this. What a delightful
surprise. Here is the code for bash/dash:
....
command | (read -r; printf "%s\n" "$REPLY"; sort)
....
The purpose of this is to keep the header and not sort it, but sort the rest.
It is for a command that produces a header when you want to keep the header.
From
https://unix.stackexchange.com/questions/11856/sort-but-keep-header-line-at-the-top
Inspired by this, I came up with this for my favorite shell, rc (of Plan9Port):
....
ps aux | {printf '%s' `{read -n 1}; sort -k4 -n} | awk '$4>=0.5 || $0~"USER"' |
less -S
....
This shows processes sorted by column 4 which is percent of memory. The awk
command excludes processes using less than one half of a percent of memory and
includes the header line. This is running on Debian fyi. I think that the
read command is from Plan9Port, and all the rest of the commands are the Debian
standards, i.e. belonging to either Linux or GNU. Here is a simpler version
that shows all processes:
....
ps aux | {printf '%s' `{read -n 1}; sort -k4 -n} | less -S
....