On Wed, Jul 03, 2024 at 06:58:27AM -0500, Ed Morton wrote:
I'd be interested to hear if you or anyone else reading this knows
of a way to read the input 1 char at a time in a case like this
where the input is unending and we can't rely on a regexp match for
RS to find each character.
Have you considered trying to use the select extension and its
nonblocking feature?
Something like this sort of seems to work:
(echo "A;B;C;D;"; cat -) | gawk -v 'RS=[;=]' -lselect -ltime '
BEGIN {
fd = input_fd("")
set_non_blocking(fd)
PROCINFO[FILENAME, "RETRY"] = 1
while (1) {
delete readfds
readfds[fd] = ""
select(readfds, writefds, exceptfds)
while ((rc = getline x) > 0) {
if (rc > 0)
printf "%d [%s]\n", ++n, x
else if (rc != 2) {
print "Error: non-retry error"
exit 1
}
}
}
}'
Regards,
Andy