Linux: Block until a string is matched in a file ("tail + grep with blocking")

Viewed 16923

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.

Update: Seems like I should have emphasize that I want the process to end when the string is matched.

7 Answers

I make a variant with sed instead of grep, printing all lines parsed.

sed '/PATTERN/q' <(tail -n 0 -f file.log)

The script is in https://gist.github.com/2377029

Related