我的日志文件是键值格式。我想在 tail -f 上找到特定键的值 ..
假设日志中的一行是:
ts=2016-12-23-18-31-34-849 | deviceType=LENOVO Lenovo A6000 | elapsed=11 | firstHomePage=null | installId=37797b61-0bb1-4c1a-844c-5904c7e83de8 | ip=157.48.104.146
ts=2016-12-23-18-31-34-849 | deviceType=LENOVO Lenovo A6000 | elapsed=15 | firstHomePage=null | installId=37797b61-0bb1-4c1a-844c-5904c7e83de8 | ip=157.48.104.146
我不确定如何通过管道输出 tail -f 以便输出应遵循
11
15
最佳答案
使用GNU grep
与 --line-buffered
缓冲命令 stdout
因为它在文件不断增长的情况下到达。 -o
仅匹配模式和 -P
的标志启用 perl
款式 regEx
捕获。
tail -f file | grep --line-buffered -oP "elapsed=\K(\d+)"
11
15
来自
man grep
页,--line-buffered
Use line buffering on output.
关于bash - 如何在tail -f上找到键的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41302028/