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!

有帮助吗?

解决方案

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'

其他提示

This should work for you:

tail -f my_log_file | grep -o 'response_time [0-9]+ms'
sed -u 's/.* \(response_time [0-9]\{1,\}ms\) .*/\1/" my_log_file

-u is a stream version of Input/Output. Work until first EOF (so a script using echo >> my_log_file add to end of file but with an EOF at each action and thus stop the sed, tail will wait an interruption from outside)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top