Is there some one-line way in bash/GNU tools to block until there\'s a string matched in a file? Ideally, with timeout. I want to avoid multi-line loop.
Upda
$ tail -f path | sed /pattern/q
or, if you want to suppress the output of non-matching lines:
$ tail -f path | sed -n '/pattern/{p; q;}'
A simple-minded way to add a timeout is to do:
$ cmd& sleep 10; kill $! 2> /dev/null
(Suppress the errors from the kill so that if the process terminates before the time expires, you don't get the "No such process" warning). Note that this is not at all robust, since it is possible that cmd will terminate and the pid count will wrap around and some other command will have that pid by the time the timer expires.