Given the discussion of head, tail within sort, how about drop. Drop ±n to
drop the first ±n lines. If negative, drop the last n lines (All done before
the sort). Regards
Leslie
Mr. Leslie Satenstein
Montréal Québec, Canada
From: Davide Brini <[email protected]>
To: [email protected]
Sent: Wednesday, November 19, 2014 4:04 AM
Subject: Re: sort : skipping "header" row(s) - possibile new command line
option?
On Wed, 19 Nov 2014 15:21:35 +1100, Bradley Dean <[email protected]>
wrote:
> It's often possible to do this by looking at the data twice (once to
> grab the header, once to sort) - either by dumping to a file or by
> running the generating command twice.
>
> For example - take some_command which outputs space-delimeted data with
> 1 header row and a fourth numeric column I'd like to sort on:
>
> some_command > templog; head -1 templog; tail -n +2 templog | sort -n
> -k 4
>
> I think it would frequently be handy to be able to just ask sort to keep
> the header rows aside - especially when doing things like running the
> sort inside a "watch" loop where you'd like to be able to come back to
> it over time and see what each column is.
I'm not against having an option, but in cases like this you can do
some_command | { IFS= read -r header; echo "$header"; sort -n -k4; }
can be generalized to N header lines with a read loop, eg for 3 lines:
some_command | { n=0; while [ $n -lt 3 ]; do IFS= read -r header; echo
"$header"; ((n++)); done; sort -n -k4; }
--
D.