maephisto
maephisto

Reputation: 5182

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!

Upvotes: 0

Views: 84

Answers (3)

NeronLeVelu
NeronLeVelu

Reputation: 10039

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)

Upvotes: 0

pgl
pgl

Reputation: 7981

This should work for you:

tail -f my_log_file | grep -o 'response_time [0-9]+ms'

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328556

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'

Upvotes: 1

Related Questions