tail -f and awk
Techie one this. I wanted to do this:
tail -f filename | awk '{ ...; exit}'
However this didn’t work – originally I thought awk had the pipe open, but it turned out that actually it was the tail hanging around and not dying (why it doesn’t acknowledge the SIGPIPE that I think it’ll get I’ve no idea).
Anyhow, after much anquish here’s the solution:
awk '{ ...; exit}' <(tail -f filename)
Hopefully this will save someone else some pain. You might want to check the “–follow=name” option for tail too. If you just want to stop when you hit a particular word, you could use
grep -m 1 name <(tail -f filename)
Keywords: tail -f; pipe; awk hanging
Posted: June 26th, 2006 under Linux.
Comments: 2
Comments
Comment from shenni
Time: Thursday 12 April, 2012, 03:52
Thanks a lot!
I was having the problem you described.
Comment from Jimmetry
Time: Friday 11 November, 2011, 01:47
I had this working from the terminal but not from PHP’s shell_exec() and I couldn’t work out why. Thanks heaps. I’ve been stuck on this problem for way longer than I’d like to admit…