The problem

To run a command which outputs tabular text data where you'd like to sort on a column but leave the header row(s) at the top.

The solution (well, a solution)

I asked the GNU coreutils guys here but also discussed earlier here with a workaround using sed with option:

-u, --unbuffered : load minimal amounts of data from the input files and flush the output buffers more often

This work-around is non-portable depending on your sed, but if it does work it's not much typing and works:

Given a command with 3 header rows, and a 4th numeric column which you'd like to sort descending:

my_command | ( sed -u 3q && sort -n -r -k 4 )

Or a working example - say I want to watch a mysql server using mysqladmin processlist, skipping sleeping threads, and sorting by longest running-time descending:

$ watch -n 5 'mysqladmin processlist | grep -v Sleep | ( sed -u 3q && sort -r -n -k 12 )'

BradsWiki: Skipping header rows with sort (last edited 2014-11-20 06:38:29 by BradleyDean)