At Wed, 24 Apr 2019 09:25:58 +0200, Andreas Krey <[email protected]> wrote: Subject: Re: uniq on open streams > > On Tue, 23 Apr 2019 11:50:23 +0000, Greg A. Woods wrote: > ... > > > > Thinking "Oh, so it should work on FreeBSD too...", I opened a window to > > my recently installed FreeBSD-12.0 machine, and after rewriting the Lua > > code into AWK, I was surprised to see absolutely no output at all! > > stdout buffering is a thing. awk may not flush stdout, esp. when > stdout is not a terminal. So uniq may not get anything. > > (echo a; echo b; echo c; sleep 3) | uniq -c > > is test case enough, and doesn't have the stdout buffer issue.
Awk does seem to flush stdout even when it feeds a pipe (and
incidentally has an "fflush" function just in case), but I've actually
ended up using:
{ echo a; echo b; echo c; read junk; } | uniq-apple
(Awk has "getline" too, but the shell variant is easier to type!)
Note, as this hints the Apple version (text_cmds-99) of FreeBSD's uniq
will build and run fine on NetBSD (with -D__APPLE__), and it does show
the 'c' line immediately.
However there's been so much churn (and what seems like entirely
unnecessary and mis-guided localization) both before and after that
version that I don't think it's useful to look at, though it does give a
hint as to how the algorithm might be changed for certain combinations
of command-line options to achieve the effect of printing each line
immediately when it differs from the line before (instead of only
printing the previous line, possibly with a count, when the current line
differs or EOF has been reached).
I don't see that changing this behaviour would ever be terribly useful
though since as you mentioned, stdout buffering is a thing (i.e. seeing
the output immediately only works if uniq's stdout is the tty. If it's
not the end of the pipeline then it will buffer its output too.
--
Greg A. Woods <[email protected]>
+1 250 762-7675 RoboHack <[email protected]>
Planix, Inc. <[email protected]> Avoncote Farms <[email protected]>
pgpMBrGO6AQez.pgp
Description: OpenPGP Digital Signature
