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.

Solution

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

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


3 comments:

  1. We have identified the list of available devices for Amazon Prime Video; we can also check out the step by step to activate Primevideo.com/mytv on your smart TV. We only need a prime video activation code for the activation method. You can create the activation code on your device with the occasional help of Prime Video application. With this information handy, you can get a unique code and initiate their devices in less than one minute.
    Read more…

    ReplyDelete