In unix everything is a file. That goes for streams too. So you can use unix tools designed for files on streams. For instance the
tail command prints the tail of a file. With the
-f argument, it creates a stream of the bytes that are appended to the file it works on. The
grep allows you to search for content in a file. Combined, we can use those two tools to selectively print new stuff that becomes appended to a file. This was useful for me today as I'm migrating a lot of data and creating a log in the process. I'd like to keep an eye on said log for signs of problems. Simply using
tail -f prints all the content. Most of which are status updates of things that go right, making it hard to spot the few times when it doesn't go right. But by combining it with
grep we can filter away those updates and only show when lines containing the word "error" is added to the log.
tail -f log.txt | grep "error"