I figured this out and it seems to work well even on large 10,000 files. It can be written more elegantly and improved though.
The r3awk function takes an STDIN and a block of code that it executes on each line, binding a string variable to it:
r3awk: func [ code /local a lines line partial ] [ partial: copy "" lines: read/lines/string system/ports/input while [ not empty? lines ] [ lines/1: rejoin [ partial lines/1 ] partial: pull lines foreach line lines [ do bind code 'line ] if error? try [ lines: read/lines/string system/ports/input ] [ lines: copy [] ] ] line: partial do bind code 'line ]
It works like that. read / line reads a few characters from the stream and returns a block of lines. Each time it is called, it reads the next batch of such characters, so that all this ends in a while loop. The code processes (makes a block of code) like while loops (and not at the end).
The batch of characters does not end on a new line, so the last line is partial every time. And this is the first line in the next batch, so it brings them together. In the end, he should process the last (this time not partial) line. Try it because some lines caused utf coding errors.
It can be used on the command line:
(echo "first line" ; echo "second line" ; echo "third line" ) | \ r3 --import utils.r --do 'r3awk [ parse line [ copy x to space (print x) ] ]' first second third
What needs to be improved: itβs better to make the function better, to deduplicate some code. Check what happens if reads / lines end exactly on a new line.
source share