Do a tail -F until matching a pattern

后端 未结 10 1393
遥遥无期
遥遥无期 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 09:52

    Here's an extended version of Jon's solution which uses sed instead of grep so that the output of tail goes to stdout:

    sed -r '/EOF/q' <( exec tail -n +0 -f /tmp/foo ); kill $! 2> /dev/null
    

    This works because sed gets created before tail so $! holds the PID of tail

    The main advantage of this over the sh -c solutions is that killing a sh seems to print something to the output such as 'Terminated' which is unwelcome

提交回复
热议问题