Struggling to think of a brief title, so sorry about that. The goal is to read from a stream of data, say for instance 'tail -f' a log file, but stop after a predetermined number of matches with grep.
I was thinking this would be a good use of an until loop but with what I have currently the tail would never be terminated, and even if it were the data couldn't be used afterwards (say if we wanted to print it to the screen).
until [ $(tail -f /var/log/messages | grep "string" | wc -l) -eq "3" ]; do sleep 1; done
[link][7 comments]