亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

返回參數sed / grep / awk / gawk中的字符串

返回參數sed / grep / awk / gawk中的字符串

慕婉清6462132 2021-04-01 13:10:23
需要一些幫助來返回2個特定定界符內的日志文件中的所有數據。我們通常有以下日志:2018-04-17 03:59:29,243 TRACE [xml] This is just a test.2018-04-17 13:22:24,230 INFO [properties] I believe this is another test.2018-04-18 03:48:07,043 ERROR [properties] (Thread-13) UpdateType: more data coming here; ProcessId: 50102018-04-17 13:22:24,230 INFO [log] I need to retrieve this string hereand also this one as it is part of the same text2018-04-17 13:22:24,230 INFO [det] I believe this is another test.如果我將grep設為“ here”,則僅獲得包含單詞的行,但實際上我需要檢索整個文本,則中斷可能也導致了我的問題。2018-04-17 13:22:24,230 INFO [log] I need to retrieve this string hereand also this one as it is part of the same text我們可以在日志文件中有幾個“這里”。我試圖通過sed做到這一點,但是我找不到正確的方法來使用定界符,我認為這應該是整個DATE。
查看完整描述

2 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

與GNUawk多字符記錄分隔符


$ awk -v RS='(^|\n)[0-9 :,-]+' '/here/{print rs,$0} {rs=RT}' file


2018-04-18 03:48:07,043  ERROR [properties] (Thread-13) UpdateType: more data coming here; ProcessId: 5010


2018-04-17 13:22:24,230  INFO [log] I need to retrieve this string here

and also this one as it is part of the same text

注意:在這里,我通過創建使用時間戳記中的值的記錄分隔符來作弊。您可以精確地制定它,以消除出現在第二行開頭的誤報?;蛘撸部梢詫⒄{試級別添加到匹配項中。


查看完整回答
反對 回復 2021-04-16
  • 2 回答
  • 0 關注
  • 314 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號