[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: difference in RS handling for equivalent regexps with unending input
From: |
Andrew J. Schorr |
Subject: |
Re: difference in RS handling for equivalent regexps with unending input stream |
Date: |
Fri, 5 Jul 2024 10:42:34 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi Ed,
OK, fair enough. Having wasted all of this time on this solution, I'm
wondering if it should be posted in response to the stackoverflow question,
but for some reason, Stackoverflow won't let me create an account. Perhaps
you could share there.
Regards,
Andy
On Thu, Jul 04, 2024 at 05:03:01AM -0500, Ed Morton wrote:
> Thanks Andy but unfortunately I'm not able to install any extensions such as
> the "select" library that don't just come with the gawk installation on my
> work
> computer (where I most need to develop/use solutions to problems) and so I
> avoid doing so on my personal one too to keep the tools I use on both as
> similar as possible. So I won't be able to try your suggestion.
>
> Ed.
>
> On 7/3/2024 12:22 PM, Andrew J. Schorr wrote:
>
> 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
>
>
>
--
Andrew Schorr e-mail: aschorr@telemetry-investments.com
Telemetry Investments, L.L.C. phone: 917-305-1748
147 W 35th St, Ste 1106
New York, NY 10001-2140