I have not put all snippets in place, but how about this piece of
plumbing... use a "lookup" to number the multiple occurrences of w2 (like
"unique count" but with "lookup" you can do without sorting it). Make it a
subroutine pipeline

´callipe *: l: lookup autoadd before count trackcount w2 detail master |
spec w1.2 1 ,:, n read 1.10 strip n | *:

This produces output like
8000 3339:1
8001 10017:1
8002 3339:2

Use the same subroutine to number the w2 in both file1 and file2, and now
use "lookup w2" to pair them. And now SMOP will remove that sequence number
again when joining the matched detail and master:  l:lookup w2 detail
master|spec fs : f1 1 read w1 nw

6000 10017 8001
6001 3339 8000
6002 3339 8002

And you probably need to do something about the ones that did not have a
match...

Happy Plumbing.
Sir Rob the Plumber

On 23 June 2015 at 20:04, Glenn Knickerbocker <[email protected]> wrote:

> On 6/23/2015 7:35 AM, Alain Benveniste wrote:
> > Based on key cyls I want to match line1 of file1 with the first line
> > in line 2 that has the same cyls value. When picked up, the line in
> > file2 can not be reselected.
>
> I'm kind of surprised I never had to tackle this same problem.  Sadly,
> there's no COLLATE PAIRWISE or LOOKUP AUTODELETE.  And, actually, even
> using LOOKUP ALLMASTERS to keep multiple reference records with the same
> key, when you delete a reference record, all the records matching the
> key are deleted at once, so you'd have to pick out the first match to
> delete it, and then add the rest back in.
>
> The timing of the feedback gets tricky, and I -did- come up with a neat
> trick for that a while back:  Instead of loosening things up with COPY
> or ELASTIC, use CHOP and FANINANY to feed a null record to the input of
> BUFFER 1, to delay the records on the alternate streams by just the
> right amount.
>
> 'PIPE (end /)' etc.          , /* primary input here */
>   '| after: chop not 00-ff'  , /* send null below */
>   '| match: lookup' whatever , /* match up records */
>   '| wait: faninany'         , /* add in null below */
>   '| buffer 1'               , /* delay output until null */
>   '| locate'                 , /* skip null */
>   more processing here       , /* feedback, other inputs to match: */
>   '/ after:'                 ,  /* null from above */
>   '| wait:'                  ,  /* add to output above */
>
> After LOOKUP releases its input record, CHOP writes a null record to its
> alternate, flushing the buffer, and BUFFER writes all the output for
> that record before CHOP can pass the next input record to LOOKUP.  That
> way, you know LOOKUP has had a chance to handle all the records you feed
> back before it reads the next input record.
>
> ¬R
>

Reply via email to