Do a tail -F until matching a pattern

后端 未结 10 1372
遥遥无期
遥遥无期 2020-11-28 09:21

I want to do a tail -F on a file until matching a pattern. I found a way using awk, but IMHO my command is not really clean. The problem is that I need to d

10条回答
  •  执笔经年
    2020-11-28 10:08

    Try this:

    sh -c 'tail -n +0 -f /tmp/foo | { sed "/EOF/ q" && kill $$ ;}'
    

    The whole command-line will exit as soon as the "EOF" string is seen in /tmp/foo.

    There is one side-effect: the tail process will be left running (in the background) until anything is written to /tmp/foo.

提交回复
热议问题