我的日志文件每行有一个json对象。我使用json通过以下方式获得人类可读的输出
cat mylog.log | json -a field1 field2现在我想要
tail -F mylog.log | json -a field1 field2以获得连续输出。但这似乎不起作用,外壳只是挂起了。如果我使用&|来避免缓冲问题,输出就像我只运行cat一样。
mylog.log看起来像这样:
{"field1": entry1a, "field2": entry2a, "field3": entry3a}
{"field1": entry1b, "field2": entry2b, "field3": entry3b}有什么建议吗?
发布于 2012-03-12 21:46:10
它看起来像json first loads the whole stdin into a buffer and only then processes the data,但您仍然可以通过为添加到日志文件中的每一行调用它来实现流处理,如下所示:
tail -F mylog.log | while read line; do echo "$line" | json -a field1 field2; donehttps://stackoverflow.com/questions/9667675
复制相似问题