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

后端 未结 7 1701
小蘑菇
小蘑菇 2020-12-05 11:58

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

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 12:44

    tail -f file | grep word | head -n1
    

    Will post snip with async timeout

    For now: How to include a timer in Bash Scripting?

    The linked answer defines a 'run_or_timeout' function that does what you are looking for in a very bash-savvy way

提交回复
热议问题