On 8/12/2014 1:12 PM, James Vincent wrote:
> 0001 data$blah$blah$data$KEY$BETTER$data$data$data$blah
> 0002 data$blah$blah$data$data$data$data$blah$KEY$MOREBETTER$data$data
>
> I'd like to get to:
>
> 0001 BETTER
> 0002 MOREBETTER
For a single field, CHOP does the trick:
... | not chop after string "$KEY$" | chop $ | ...
If the record number you show here is part of the actual data, you'd
have to handle it separately:
(end /) ... | num: chop after blank | key: gather | join 1 | ...
/ num: | not chop after string "$KEY$" | chop $ | key:
Note that you might want JUXTAPOSE in place of GATHER|JOIN if you won't
always copy the record on the alternate. You don't need JUXTAPOSE if
you can select the records *before* chopping them up--if you want only
the records with $KEY$ in them, for instance:
(end /) ... | locate "$KEY$"
| num: chop after blank | key: gather | join 1 | ...
/ num: | not chop after string "$KEY$" | chop $ | key:
But suppose you wanted only keys with a "2" in them. You'd have to make
that selection after pulling out the key:
(end /) ... | num: chop after blank | key: juxtapose | ...
/ num: | not chop after string "$KEY$" | chop $ | locate "2" | key:
(You could use JUXTAPOSE in all three cases. Using GATHER where
appropriate has a performance advantage, since it doesn't have to check
both input streams after every record. It also helps catch when you've
made an error in your pipelines and they don't produce records in the
order you thought they should.)
¬R