Tail a log file for specific strings

I needed to tail a logfile in realtome for specific strings to understand why mpd was failing to update all of my music. To do this I tail the log file as follows:

tail -f filetofollow

This follows the output of the log file, however this includes everything; including a lot of unwanted noise.

Grep can be used to search through text for specific strings, filtering out the noise.

Tail can be piped into grep, however grep will only run once tail has completed. This means on a continual log file you cannot see grep results as the log is created, only post the log being created and tail completing.


tail -f filetofollow | grep --line-buffered stringtofind

This follows the log file as it is created, only printing lines containing the strings required.

No comments:

Post a Comment