Fork me on GitHub

I don't know who needs to hear this, but I got bitten by grep's stdio buffering behaviour today. Frankly I'm astonished it did not bite me all this time! Here is TL;DR, copied from the post: This will apparently do nothing (really, it's just buffering)...

$ tail -f /var/log/foo | grep -E -v 'some|stuff' | sed | awk
Using stdbuf -o0 fixes it (presumably with performance penalty, because of force-flushing every line to stdout).
$ tail -f /var/log/foo | stdbuf -o0 grep -E -v 'some|stuff' | sed | awk

gratitude-thank-you 1

If MODE is 'L' the corresponding stream will be line buffered.  This
       option is invalid with standard input.
I’ve never used this before, but based on the man page, I think -o0 means flush with every byte. I wonder if -oL would be a bit faster and still do what you intend.

Cora (she/her)18:05:27

there's also unbuffer, a cli tool that is part of TCL expect

👀 1

@U060KDHA6 thanks for the reference! Guess who read the blog post but not the manpage?

😂 1

I’d guess it doesn’t make too much of a difference in practice, as the producer is probably producing things in larger chunks in most cases anyway.

👍 1

This minor snafu was on the way to getting a form of hot reload to work in the little static site generator I'm yak-shaving making for myself... And the reload is heating up!