[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: add "min" and "max" to coreutils?
From: |
Jim Meyering |
Subject: |
Re: add "min" and "max" to coreutils? |
Date: |
Fri, 03 Jul 2009 10:53:02 +0200 |
Pádraig Brady wrote:
> Joshua Bronson wrote:
>> I was looking for a command line utility to get the min and max from a file
>> (rather than the much less efficient "sort | {head,tail} -1") and I couldn't
>> find one. Someone on linuxquestions.org directed me toward the Generic
>> Mapping Tools <http://gmt.soest.hawaii.edu/>, which provide a "minmax"
>> utility, and though it would get the job done it's not exactly what I was
>> looking for (not to mention I have no need for the ~60 other utilities in
>> the package).
>
> Yes, http://gmt.soest.hawaii.edu/gmt/doc/gmt/html/man/minmax.html is a
> bit complicated and not very generic.
> Perhaps http://suso.suso.org/programs/num-utils/ would be
> more appropriate for you?
FYI, the normalize program from num-utils-0.5 has a bug.
It scales by the sum of the inputs rather than by the
maximum absolute value:
$ printf '%s\n' 1 99 100 100 100 | ./normalize
0.0025
0.2475
0.25
0.25
0.25
$ printf '%s\n' -1 1 | ./normalize
Illegal division by zero at ./normalize line 135, <STDIN> line 2.
>> As the provider of "sort", would coreutils be the appropriate
>> package to provide "min" and "max" tools with a similar interface (e.g.
>> accepting "-n" and such)?
>
> That's an interesting suggestion. I'm not sure about separate tools,
> especially considering the num-utils package above. Though perhaps
> adding --{head,tail} options to sort would be appropriate as one could
> then use a O(n*m) algorithm in sort where m is the parameter to --head
> and n is the number of input lines. Also it would be a lot more memory
> efficient and one would get the key processing functionality of sort.
> I'm not sure about doing that at all though.
IMHO, adding that functionality to sort would be worthwhile.
More generally, it could print an arbitrary range of sorted entries:
degenerate ranges:
1 first
n or -1 last
k k'th
1,3 first three
-3,-1 last three
This seems different enough that I wondered for a moment
if it deserved to be a separate program. Not impossible, I suppose,
but since with a range like 1,-1 it is equivalent to sort, they
would share a lot of code.
Re: add "min" and "max" to coreutils?,
Jim Meyering <=