Read text from a file or process handle
read0 f read0[f]
read0 (f;o;n) read0[(f;o;n)]
read0 h read0[h]
read0 (fifo;n) read0[(fifo;n)]
where
f is a file symbol(f;o;n) is a file descriptor
h is a system or connection handlefifo is a communication handle to a Fifon is a non-negative integerreturns character data from the source as follows.
Returns the lines of the file as a list of strings. Lines are assumed delimited by either LF or CRLF, and the delimiters are removed.
q)`:test.txt 0:("hello";"goodbye") / write some text to a file
q)read0`:test.txt
"hello"
"goodbye"
q)/ read 500000 lines, chunks of (up to) 100000 at a time
q)d:raze{read0(`:/tmp/data;x;100000)}each 100000*til 5
Returns n chars from the file, starting from the position o.
q)`:foo 0: enlist "hello world"
q)read0 (`:foo;6;5)
"world"
Returns a line of text from the source.
q)rl:{1">> ";read0 0}
q)rl`
>> xiskso
"xiskso"
Reading the console permits interactive input.
q)1">> ";a:read0 0
>> whatever
q)a[4+til 4]
"ever"
Returns n characters from the pipe.
(Since V3.4 2016.05.31)
q)h:hopen`$":fifo:///etc/redhat-release"
q)read0(h;8)
"Red Hat "
q)read0(h;8)
"Enterpri"