此解決方案將成爲腳本的一部分。在bash中從行中提取兩個子字符串,然後連接它們
給定一個錯誤日誌,我需要提取失敗的狀態/失敗原因和用戶名,然後連接它們以便輸出可以通過電子郵件發送。
我的輸出應該是這個樣子:
Operation status: failed,Job Description not updated because this is not a matching Job Description ID.,username=FOO
Operation status: failed,Job Description not updated because this is not a matching Job Description ID.,username=BAR
在錯誤日誌文件中的每一行非常類似於此:
"{ Operation status: failed,Job Description not updated because this is not a matching Job Description ID.,Sent Data:{lastAppraisalScore=0.0, country=null, jobTitle=LABORER..., username=FOO},...sendAcctActNotif=N}}"
有文件中沒有省略號;每一行所包含的內容都比所示的多得多,但我只顯示了重要的部分。
你能分享一下你的研究工作嗎?你是否嘗試用'set -x'選項來調試腳本? – Inian
每行是否有效JSON?如果是這樣,你可以通過將每行傳遞給'jq'並選擇'Operation status'和'username'鍵來實現。 –
我還沒有嘗試用'set -x'選項進行調試。 'egrep -o「操作狀態:」輸入「部分地返回我需要的內容,但需要提取直到第一個」。「,這樣我才能拾取整個錯誤代碼。 – sharpmartin6