2016-06-28 93 views
-3

我的系統在日誌中生成很長的行,我只想grep只有幾個字段的值。我嘗試了grep和sed,而且我離得很近。grep特定的字符串在單行中出現多次

這裏,單日誌行包含多個通道字段及其分析。 如何從包含許多此類渠道信息的單個日誌行中獲取特定渠道(發生多次)。 例如在這裏我需要視頻頻道分析,它發生兩次。

....... { 「通道」:{ 「類型」: 「視頻」, 「協議」: 「DYNAMIC_96」, 「速度」: 「1999102」, 「包」:{」轉發「:{」Total「:」570495「,」RTPAndRTCP「: 」570495「,」KeepAlives「:」0「,」Unknown「:」0「},」KeepAlives「:{」Total「: 」0 「,」同意「:」0「,」H460「:」0「,」STUN「:」0「},」錯誤「:{」Total「: 」0「,」Media「:{」NoDestination「 「0」,「InvalidType」:「0」,「FilterFailure」: 「0」,「MediaDiscarded」: 「0」,「Filter」:{「SRTP」:{「Decrypt」:{「Authentication」 0「,」解密「: 」0「,」BadRTPHeader「:」0「,」FECIgnored「:」0「,」其他「: 」0「}},」RTP「:{」Payload「重寫「:{」Unexpected「: 」0「}}}}},」Ass ent「:{」InvalidProbe「:」0「},」IP「:{」Send「: 」0「}},」Analysis「:{」Duplicate「:」0「,」Lost「:」4「, 「OutOfOrder」: 「1」,「Unexpected」:「0」,「Jitter」:「8」,「JitterPeak」: 「48」}},「Incoming」:{「Leg」:「BSide」 「Outgoing」:{「Leg」: 「ASide」}}},..................... {「Channel」:{「Type」: 「視頻「,」協議「:」DYNAMIC_96「,」費率「: 」1617864「,」數據包「:{」轉發「:{」總數「:」407214「,」RTPAndRTCP「: 」407214「 :「0」,「Unknown」:「0」},「KeepAlives」:{「Total」: 「0」,「Assent」:「0」,「H460」:「0」,「STUN」:「0 「}」,「錯誤」:{「Total」: 「0」,「媒體」:{「NoDestination」:「0」,「無效類型」:「0」,「FilterFailure」: 「0」「MediaDiscarded」 :「0」,「Filter」:{「SRTP」:{「Encrypt」:{「Encrypt」: 「0」,「BadRTPHeader」: 「0」,「FECIgnored」:「0」,「DatagramSizeExceeded」: 「0」,「其他」:「0」}},「RTP」:{「Payload」:{「Rewrite」:{「Unexpected」 「」異常「:{」InvalidProbe「:」0「},」IP「:{」發送「: 」0「}},」分析「:{」Duplicate「:」 0「,」丟失「:」1045「,」OutOfOrder「: 」0「,」意外「:」957「,」抖動「:」3「,」JitterPeak「: 」1143「}} :{ 「腿」: 「除了」}, 「呼出」:{ 「腿」: 「BSide」}}},......

我對只在上述這些2聲道分析並拋出所有等等等等信息。

任何指針都會有很大的幫助。謝謝 !!

+0

請[編輯],並顯示什麼是確切的預期輸出。 – fedorqui

+0

上述輸入文件中的換行已重新格式化。要粘貼某些代碼中的文本,請使用*「{}」*(代碼示例)按鈕,而不是*'「'*(Blockquote)按鈕。_Blockquote_默認重新格式化文本,_Code Sample_不會。 – agc

回答

0

要想從線上的渠道,你可以使用:

grep -Eo '"Channel":{[^{]+({[^}]+})+}' 

這將輸出爲您例如:

"Channel":{"Type": "Video","Protocol": "DYNAMIC_96","Rate": "1999102","Packets":{"Forwarded":{"Total": "570495","RTPAndRTCP": "570495","KeepAlives": "0","Unknown": "0"},"KeepAlives":{"Total": "0","Assent": "0","H460": "0","STUN": "0"},"Errors":{"Total": "0","Media":{"NoDestination": "0","InvalidType": "0","FilterFailure": "0","MediaDiscarded": "0","Filter":{"SRTP":{"Decrypt":{"Authentication": "0","Decrypt": "0","BadRTPHeader": "0","FECIgnored": "0","Other": "0"}} 
"Channel":{"Type": "Video","Protocol": "DYNAMIC_96","Rate": "1617864","Packets":{"Forwarded":{"Total": "407214","RTPAndRTCP": "407214","KeepAlives": "0","Unknown": "0"},"KeepAlives":{"Total": "0","Assent": "0","H460": "0","STUN": "0"},"Errors":{"Total": "0","Media":{"NoDestination": "0","InvalidType": "0","FilterFailure": "0","MediaDiscarded": "0","Filter":{"SRTP":{"Encrypt":{"Encrypt": "0","BadRTPHeader": "0","FECIgnored": "0","DatagramSizeExceeded": "0","Other": "0"}} 
相關問題