sorthead [-tail] [-down] [-nullsfirst] <nrows> <key-list>
Performs a sort on the table according to the value of
one or more algebraic expressions, retaining only
<nrows> rows at the head
of the resulting sorted table.
The sort key expressions appear,
as separate (space-separated) words,
<key-list>; sorting is done on the
first expression first, but if that results in a tie then
the second one is used, and so on.
Each expression must evaluate to a type that
it makes sense to sort, for instance numeric.
-tail flag is used, then the
<nrows> rows rather than the first
ones are retained.
-down flag is used the sort order is
descending rather than ascending.
Blank entries are by default considered to come at the end
of the collation sequence, but if the
flag is given then they are considered to come at the start
This filter is functionally equivalent to using
sort followed by
but it can be done in one pass and is usually cheaper
on memory and faster, as long as
is significantly lower than the size of the table.
Syntax for the
<key-list> argument is described in Section 9.