Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17822

Bash oneliner to read from stream until X number of lines?

$
0
0

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 
submitted by spandexbandana
[link][7 comments]

Viewing all articles
Browse latest Browse all 17822

Trending Articles