On 2019-08-14 12:45 PM, [email protected] wrote:
> In a file I have every now and then a record tagged at the
> beginning, all other lines begin with blanks. I'd like to change
> the sequence of tagged records with the one directly following it
> (which is for sure not tagged).
A way that's a little tricky but avoids messing with combining records
is to use DROP LAST to delay a copy of the file by one record, and keep
the tagged records from that stream. Note that I would normally add a
new last record to drop with STRLITERAL APPEND, but if you know the last
record won't be tagged we can skip that:
(end /) ...
| dup: fanout
| strfind '_'
| all: faninany
| ...
/ dup:
| drop last 1
| strnfind '_'
| all:
If the frequency of tagged records is very small, there might be some
performance advantage to picking out and duplicating only the
pairs--saves the cost of copying the other records, but adds a third
stream for FANINANY to watch:
(end /) ...
| pair: pick from 1 ¬== ' ' count 2
| dup: fanout
| strfind '_'
| all: faninany
| ...
/ dup:
| drop last 1
| strnfind '_'
| all:
/ pair:
| all:
¬R