Site menu:

Sponsored by

Bitcube Ltd.  Expert Linux Consultancy

Categories

Meta

Site search

 

June 2006
M T W T F S S
« May   Jul »
 1234
567891011
12131415161718
19202122232425
2627282930  

Archives

Links:

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

Comments

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…

Comment from shenni
Time: Thursday 12 April, 2012, 03:52

Thanks a lot!

I was having the problem you described.