On Mon, 27 Oct 2008 23:23:18 -0000, Ian S. Worthington wrote:
>I need a way to do something like a SORT UNIQ but extracting n records not
>just the first/last one.

You need to COUNT them and PICK the ones with a small enough count:

  (end \) ... | sort ... | first: unique count ... first 
       | more: faninany | not chop 10 | ...     (first n out here)
       \ first: | less: pick 1.10 <= n | more:
       \ less: | not chop 10 | ...               (extras out here)

I've always wished we could do UNIQUE COUNT ALL and not have to FANINANY
the duplicates back in.  Note that this needs room to buffer the whole
file, and if you're using the extras they'll be sorted too.  If the
extras don't have to be sorted, LOOKUP TRACKCOUNT AUTOADD can number them
without buffering them (though you still need room to buffer the unique
keys):

  (end \) ... | lookup trackcount autoadd before keyonly ... 
       | specs 1-* 11 read 1.10 1 | less: pick 1.10 <= n
       | not chop 10 | sort ...                 (first n out here) 
       \ less: | not chop 10 | ...               (extras out here)

If you want the last n instead of the first n, output 2 of LOOKUP COUNT
AUTOADD ALLMASTERS will have the counts in reverse, since the first
record added will match all the rest, while the last added matches only
itself.  Again, this will buffer the whole file and sort the extras:

  (end \) ... | count: lookup count autoadd before ... allmasters
       \ count: \ count: | less: pick 1.10 <= n
       | not chop 10 | ...                      (first n out here) 
       \ less: | not chop 10 | ...               (extras out here)

¬R

Reply via email to