Unix 使用两个管道会产生空结果
我正在使用varnishlog命令并尝试筛选一些字段:Unix 使用两个管道会产生空结果,unix,grep,varnish,Unix,Grep,Varnish,我正在使用varnishlog命令并尝试筛选一些字段: sudo varnishlog -c | grep -E 'ReqURL|Varnish-Cache' - ReqURL /sample/2 - RespHeader X-Varnish-Cache: HIT - ReqURL /sample/2 - RespHeader X-Varnish-Cache: HIT 现在,如果我使用另一个grep命令,我会得到空结果: su
sudo varnishlog -c | grep -E 'ReqURL|Varnish-Cache'
- ReqURL /sample/2
- RespHeader X-Varnish-Cache: HIT
- ReqURL /sample/2
- RespHeader X-Varnish-Cache: HIT
现在,如果我使用另一个grep命令,我会得到空结果:
sudo varnishlog -c | grep -E 'ReqURL|Varnish-Cache' | grep 'HIT'
你能帮我一下这里有什么问题吗
命令的示例输出:sudo varnishlog-c
* << Request >> 658516
- Begin req 658515 rxreq
- Timestamp Start: 1478508065.780332 0.000000 0.000000
- Timestamp Req: 1478508065.780332 0.000000 0.000000
- ReqStart 10.56.36.2 55578
- ReqMethod GET
- ReqURL /sample/2
- ReqProtocol HTTP/1.1
- ReqHeader Host: localhost:6081
- ReqHeader User-Agent: Mozilla/5.0 Firefox/44.0
- ReqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- ReqHeader Accept-Language: en-US,en;q=0.5
- ReqHeader Accept-Encoding: gzip, deflate
- ReqHeader Connection: keep-alive
- ReqHeader Pragma: no-cache
- ReqHeader Cache-Control: no-cache
- VCL_call RECV
- VCL_return hash
- ReqUnset Accept-Encoding: gzip, deflate
- ReqHeader Accept-Encoding: gzip
- VCL_call HASH
- VCL_return lookup
- Hit 658416
- VCL_call HIT
- VCL_return deliver
- RespProtocol HTTP/1.1
- RespStatus 200
- RespReason OK
- RespHeader Content-Length: 4774
- RespHeader Last-Modified: Tue, 12 Apr 2016 17:42:58 GMT
- RespHeader Etag: f9d34a65e8c1b30245c2f12534348ff9
- RespHeader X-Timestamp: 1460482977.61998
- RespHeader Content-Type: image/png
- RespHeader X-Trans-Id: txf52283ea65004e578ddfe-0058203d84
- RespHeader Date: Mon, 07 Nov 2016 08:38:28 GMT
- RespHeader X-Varnish: 658516 658416
- RespHeader Age: 157
- RespHeader Via: 1.1 varnish-v4
- VCL_call DELIVER
- RespHeader X-Varnish-Cache: HIT
- VCL_return deliver
- Timestamp Process: 1478508065.780379 0.000047 0.000047
- RespHeader Accept-Ranges: bytes
- Debug "RES_MODE 2"
- RespHeader Connection: keep-alive
- Timestamp Resp: 1478508065.780411 0.000079 0.000032
- ReqAcct 415 0 415 393 4774 5167
*>658516
-开始请求658515 rxreq
-时间戳开始:1478508065.780332 0.000000 0.000000
-时间戳请求:1478508065.780332 0.000000 0.000000
-需求启动10.56.36.2 55578
-ReqMethod获取
-请求URL/sample/2
-REQ协议HTTP/1.1
-ReqHeader主机:本地主机:6081
-ReqHeader用户代理:Mozilla/5.0 Firefox/44.0
-ReqHeader接受:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-请求头接受语言:en-US,en;q=0.5
-ReqHeader接受编码:gzip,deflate
-ReqHeader连接:保持活动状态
-ReqHeader杂注:无缓存
-ReqHeader缓存控制:无缓存
-呼叫记录
-返回哈希
-ReqUnset接受编码:gzip,deflate
-ReqHeader接受编码:gzip
-调用哈希
-返回查找
-点击658416
-呼叫命中
-返回交付
-resp协议HTTP/1.1
-反应状态200
-好的
-标题内容长度:4774
-最后修改时间:2016年4月12日星期二17:42:58 GMT
-响应:f9d34a65e8c1b30245c2f12534348ff9
-RespHeader X时间戳:1460482977.61998
-RespHeader内容类型:图像/png
-应答器X-Trans-Id:txf52283ea65004e578ddfe-0058203d84
-回复日期:2016年11月7日星期一08:38:28 GMT
-RespHeader X-清漆:658516 658416
-年龄:157
-RespHeader过孔:1.1 varnish-v4
-呼叫传送
-RespHeader X-Varnish-Cache:命中
-返回交付
-时间戳进程:1478508065.780379 0.000047 0.000047
-RespHeader接受范围:字节
-调试“恢复模式2”
-RespHeader连接:保持活动状态
-时间戳响应:1478508065.780411 0.000079 0.000032
-要求4150 415 393 4774 5167
您可以在grep中使用--line buffered选项,如下所示
sudo varnishlog -c | grep --line-buffered -E 'ReqURL|Varnish-Cache' | grep --line-buffered 'HIT'
曼格雷普
--行缓冲
在输出上使用行缓冲。这可能会导致性能损失
尝试将第一个grep模式用括号括起来。像这样:'(ReqURL | Varnish Cache)'。此外,UNIX版本和varnishlog-c输出的一部分将非常有用。您可以尝试使用-u无缓冲输出。像varnishlog-cu…@sotona一样,我尝试使用括号,但问题相同。我已经用命令的示例输出更新了我的帖子。@MustafaDOGRU,varnishlog命令没有I-u标志。你可以使用--line buffered选项grep像grep--line buffered…你能检查我的其他帖子吗?答案是由Inian给出的,存在类似问题,但使用的命令有带wile循环的
awk
和sed