Search code examples
regexshellunixtail

tailing log file and only showing a specific value


I'm currently tailing a log fine using

tail -f my_log_file

each line added in the log file looks like:

blaaa blaaa something blaa blaa response_time 100ms blaa blaaaaa
blaaa blaaa something blaa blaa response_time 150ms blaa blaaaaa
blaaa blaaa something blaa blaa response_time 90ms blaa blaaaaa

what i would really like is to be able to tail this log file, but only display

response_time 100ms
response_time 150ms
response_time 90ms

Is there a way to do this with "tail" ? Thanks!


Solution

  • You can pipe the output of tail through sed and grep to filter it. Try:

    tail -f my_log_file | sed -e 's/.*\(response_time \S\+\).*/\1/p'