[Top][All Lists]

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

Re: add "min" and "max" to coreutils?

From: Joshua Bronson
Subject: Re: add "min" and "max" to coreutils?
Date: Thu, 2 Jul 2009 16:15:49 -0400

2009/7/2 Pádraig Brady <address@hidden>

> 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?

It would, thank you.
http://suso.suso.org/programs/num-utils/man1/bound.htmlis definitely
more like what I had in mind.

> 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.

The more general idea of having "sort" accept an argument to output only the
k largest or smallest elements was another idea I had and would love to see
implemented. FWIW, though it provides "bound", num-utils does not seem to
provide a facility for top (bottom) k. Also, the comparative prevalence of
coreutils versus num-utils is another compelling reason to add it here.

I'm not sure about doing that at all though.

What are your concerns?

> Pádraig.

Thanks for your reply.


P.S. http://en.wikipedia.org/wiki/Selection_algorithm has a relevant section
(search for "Selecting k smallest or largest elements").

reply via email to

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