Pregunta

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!

¿Fue útil?

Solución

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'

Otros consejos

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)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top