I am trying to make an awk like tool that uses Rebol 3 to process bigger text files with bash pipes and tools. I am having a problem reading STDIN line by line in Rebol 3?
For example this shell command produces 3 lines:
$ (echo "first line" ; echo "second line" ; echo "third line" )
first line
second line
third line
But the Rebol's input word reads all 3 lines at the same time. I would expect it to stop at newline as it stops if you use input interactively.
r3 --do 'while [ x: input ] [ if empty? x [ break ] print x print "***" ]'
abcdef
abcdef
***
blabla
blabla
***
But when I run it all together it reads whole input at once. I could read it all at once and split into lines, but I want it to work in a "streaming" manner as I usually cat in many 1000-s of lines.
$ (echo "first line" ; echo "second line" ; echo "third line" ) \
| r3 --do 'while [ x: input ] [ if empty? x [ break ] print x print "***" ]'
first linesecond linethird line
***
I also looked at source of input to make a similar function. I could read in character per character in a while loop and check for newlines but that doesn't seem efficient.