coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sort --head


From: Mark E. Shoulson
Subject: Re: sort --head
Date: Wed, 19 Jun 2024 14:48:10 -0400
User-agent: Mozilla Thunderbird

Turns out whatever I'm doing doesn't work right when the input is a pipe (though input redirection from a file is okay), so in addition to being incomplete, this patch is actually buggy.  Will work on it, but still hoping to hear opinions.

~mark

On 6/18/24 21:49, Mark E. Shoulson wrote:
Hi. New here, to post a patch which I hope will inspire someone to do a better job.

I can't really believe that for all these years, we still so very, very often run sort(1) and pipe it through head(1) or tail(1), because we only want the top/bottom 20 lines or whatever.  That means we're sorting a potentially gigantic list of lines but not caring about most of the information.

I'm attaching a patch that adds `--head` and `--tail` options to sort(1), so you say `sort --head=20` (which is equivalent to saying `sort --tail=-20` and vice-versa).  I've worked this into sort(1) VERY VERY BADLY, I'm sorry to say, but maybe someone with better familiarity with the code can do it better.  Basically, I'm special-casing out the situation when --head is active and doing my own thing with it, and then lying to the rest of the program about it.  But it works, anyway.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]