Text-Processing

grep 日誌文件並將其寫入 csv 文件

  • October 13, 2020

我根據他們的呼叫ID通過向使用者播放的編解碼器文件進行grep。有 2 個文件播放給使用者/呼叫 ID。我正在將這些 grep 輸出寫入 .csv 文件。我用了

grep -oP "(?<=$START).*?(?=$END)" $IVRLOG$Progress_log>>$CURRENTPATH/op2.csv
welcome1.g711u #(call_id1)
Announcementbui4.g711u #(call_id1)
welcome1.g711u #(call_id2)
Announcementbui4.g711u #(call_id2)

但我希望輸出為

welcome1.g711u,Announcementbui4.g711u #callid1
welcome1.g711u,Announcementbui4.g711u #callid2

                

if grep -oP “(?<=$START). ?(?= $ END)” $ IVRLOG$進度日誌;然後 echo “找到匹配” { printf “%s,” " $ target_users"; grep -oP “(?<= $ 開始)。?(?= $ END)” $ IVRLOG $ Progress_log | sed ’ $ !N;s/\n/,/’; }>> $ CURRENTPATH/E41.csv else echo “Match not found” { printf “%s\n” “$target_users”; }>> $ CURRENTPATH/E41.csv fi done 我通過針對 call_id 迭代上述程式碼得到了輸出。The required output that i got: 9188888881,welcome1.g711u,Announcementbui4.g711u 9177777772,welcome1.g711u,Announcementbui4.g711u 9166666663,welcome1.g711u,Announcementbui4.g711u 9155555554,welcome1.g711u,Announcementbui4.g711u 9144444445,welcome1.g711u,Announcementbui4 .g711u Haxiel 在這方面幫助了我。

grep -oP "(?&lt;=$START).*?(?=$END)" $IVRLOG$Progress_log&gt;&gt;$CURRENTPATH/op2.csv | 
while read line; do
grep "callid" | sed 's/()()//g'  #removing the brackets
done

您可能仍然需要處理未測試的新空間程式碼

引用自:https://unix.stackexchange.com/questions/612934