On Mon, Jul 02, 2001 at 11:55:56PM +1000, Andrew Bennetts wrote:
> > > Just need to run though a file and find the maximum number in field 2
> > > and field 3. (Two runs okay).
> >
> > Cant you just pipe it through sort and awk/sed the first line?
>
> (assuming comma delimited)
>
> sort -n -t, -r -k 2 | head -n 1 | cut -d "," -f 2
Or, to use a pile less memory :
cut -d "," -f 2 | sort -n -r | head -1
ie, trim the excess data _before_ you load it all into memory for sort.
Passing -u to sort would probably use a little less memory too if you've
got duplicate data in that column.
That said, you'd be better doing it in a way which wouldnt load anything
into memory, like awk (presuming positive numbers)
awk ' $2>A { A=$2 } $3>B { B=$3} END { print A,B } '
Perl is another option, but I doubt you could do it any smaller than the
above...
Scott.
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug