tail -F log.log | grep ResponseTime | cut -d = -f 2
I have a live log file called log.log and want to catch some matching patterns and values in it:
Example: log.log is growing and we are searching for lines that have pattern "ResponseTime = VALUE" an开发者_开发百科d we want to extract the matched VALUE:
I am executing:
tail -F log.log | grep ResponseTime | cut -d = -f 2 | tr -d " "
And I am expecting to see
VALUE1
VALUE2
.. etc
But it is not working ... what should I do?
Thank you, NaMo
===========
Thank you, it works now. I am using: inotail -f log.log | stdbuf -oL grep ResponseTime | stdbuf -oL cut -d '=' -f 2 | stdbuf -oL tr -d " "
BASH FAQ entry #9: "What is buffering? Or, why does my command line produce no output: tail -f logfile | grep 'foo bar' | awk ..."
Try changing grep
to stdbuf -oL grep
.
See BASHFAQ/009 for details.
The reason that it isn't working is that some commands don't flush STDOUT with each output. Therefore the later commands are never being passed anything.
I would use just one command after tail
such as:
tail -F t.log | sed '/ResponseTime/!d;s/ResponseTime\s+=\s+(\d+)/\\1/'
If you want to remove newlines from your output then you can any of the following:
| cut -d = -f 2|sed -e :a -e '$!N;s/\n//;ta'
| cut -d = -f 2|tr -d '\n'
| cut -d = -f 2|awk '{printf "%s",$0}'
精彩评论