尾-F log.log | grep 响应时间 |切-d=-f 2
我有一个名为 log.log 的实时日志文件,想要捕获其中的一些匹配模式和值:
示例: log.log 正在增长,我们正在搜索具有模式“ResponseTime = VALUE”的行,并且我们想要提取匹配的 VALUE:
我正在执行:
tail -F log.log | grep ResponseTime | cut -d = -f 2 | tr -d " "
我期待看到
VALUE1
VALUE2
.. etc
但它不起作用...我应该做什么?
谢谢你, NaMo
===========
谢谢,现在可以了。我正在使用: inotail -f 日志.log | stdbuf -oL grep 响应时间 | stdbuf -oL cut -d '=' -f 2 | stdbuf -oL cut -d '=' -f 2 | stdbuf -oL cut -d '=' -f 2 stdbuf -oL tr -d“”
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" and 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 " "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
BASH 常见问题解答条目 #9:“什么是缓冲?或者,为什么我的命令行不产生输出:tail -f日志文件 | grep 'foo bar' |
BASH FAQ entry #9: "What is buffering? Or, why does my command line produce no output: tail -f logfile | grep 'foo bar' | awk ..."
尝试将
grep
更改为stdbuf -oL grep
。有关详细信息,请参阅 BASHFAQ/009。
Try changing
grep
tostdbuf -oL grep
.See BASHFAQ/009 for details.
它不起作用的原因是某些命令不会使用每个输出刷新 STDOUT。因此后面的命令永远不会被传递任何东西。
我会在
tail
之后只使用一个命令,例如: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:如果您想从输出中删除换行符,则可以执行以下任一操作:
If you want to remove newlines from your output then you can any of the following: