2
私はニスコマンドの下にあります。私は必要なフィールドを取得するために、grepコマンドを使用しているGrepの複数の文字列、次に置き換えるテキスト
Begin="req 658515 rxreq",ReqURL="/sample/2", RespHeader="X-Varnish-Cache: HIT"
:
sudo varnishlog -c | grep -E 'Begin|ReqURL|Varnish-Cache'
- Begin req 658515 rxreq
- ReqURL /sample/2
- RespHeader X-Varnish-Cache: HIT
しかし、余分なコマンドを使用してスペースや改行を置き換えた場合、私は問題に直面しています。
sudo varnishlog -c | grep -E 'Begin|ReqURL|Varnish-Cache' | sed 's/ /=/g'
このコマンドでは出力が得られません。
私はsedのかtrのコマンドを使用する場合:
sudo varnishlog -c | sed 's/ /=/g'
または
sudo varnishlog -c | tr ' ' '='
を次に出力は次のとおりです。
*===<<=Request==>>=629459====
-===Begin==========req=629458=rxreq
-===ReqMethod======GET
-===ReqURL=========/sample/2
-===VCL_call=======HIT
-===RespHeader=====X-Varnish-Cache:=HIT
私はこれを使用する場合:
sudo varnishlog -c | sed 's/\t/=/g'
を
その後、出力はオリジナルと同じである:
* <<Request>> 658516
- Begin req 658515 rxreq
- ReqMethod GET
- ReqURL /sample/2
- VCL_call HIT
- RespHeader X-Timestamp: 1460482977.61998
- RespHeader X-Varnish: 658516 658416
- RespHeader X-Varnish-Cache: HIT
私の必要な出力を得るための正しい方法であるかについて、いくつかのヒントで私を助けてください。
@Sundeep、私のマシンで Perlのバージョンは次のとおりです。
perl -version
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
(with 44 registered patches, see perl -V for more detail)
@Sundeep、多分これはあなたを助けることができるsudo varnishlog -c | cat -A
$
* <<Request>> 363192 $
- Begin req 363191 rxreq$
- Timestamp Start: 1478514424.525802 0.000000 0.000000$
- Timestamp Req: 1478514424.525802 0.000000 0.000000$
- ReqStart 10.56.36.2 52583$
- ReqMethod GET$
- ReqURL /sample/2$
- ReqProtocol HTTP/1.1$
- ReqHeader Host: localhost:6081$
- ReqHeader User-Agent: Mozilla/5.0 (X11; Ubuntu;....$
- 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$
- ReqHeader X-Forwarded-For: 10.56.36.2$
- 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: 363192 658416$
- RespHeader Age: 6516$
- RespHeader Via: 1.1 varnish-v4$
- VCL_call DELIVER$
- RespHeader X-Varnish-Cache: HIT$
- VCL_return deliver$
- Timestamp Process: 1478514424.525880 0.000078 0.000078$
- RespHeader Accept-Ranges: bytes$
- Debug "RES_MODE 2"$
- RespHeader Connection: keep-alive$
- Timestamp Resp: 1478514424.525908 0.000106 0.000028$
- ReqAcct 415 0 415 394 4774 5168$
- End $
または単純 'perlの-ne「の場合(/開始| ReqURL |ワニスキャッシュ/){S/^ - \ sの* //; s/^ \ S + \ K \ s +(。* \ S)\ s */= "$ 1"、/印刷} '| 'sdo 's /、$/\ n /'' – Sundeep
@Sundeep、私はあなたのコマンドを試しました - 'sudo varnishlog -c | perl -ne 'if(/ Begin | ReqURL | Varnish-Cache /){s/^ - \ s * //; s/^ \ S + \ K \ s +(。* \ S)\ s */= "$ 1"、/印刷} '| sedの/、$/\ n/''、私は出力で何も見ていません – user3181365
@Sundeep、' sudo varnishlog -c | '/ Begin | ReqURL | Varnish-Cache /]' 'が' grep'と同じように動作している場合、perl -ne 'printを出力します。私は自分の投稿を私のperlバージョンで更新しました。 – user3181365