我有一個 zsh 腳本,它將輸出傳送到一個檔案,即
<command here> | tee -a testFile
我的問題是命令的一些輸出是字符“[]”。我不希望將這些寫入我的 testFile,但應該將其他任何內容寫入檔案(例如 ["Hello"])。如何過濾寫入我的 testFile 的內容?TIA
我希望輸出如下:
["Hello"]
["World"]
["One"]
["Two"]
.. ETC
但目前我得到的是這樣的:
[]
[]
[]
["Hello"]
["World"]
[]
[]
["One"]
[]
["Two"]
到目前為止,我已經嘗試過:
<command here> | sed -E 's/\[|\]//g' | tee -a testFile
但這也會導致錯誤的輸出(注意 [] 被替換為空,然后作為新行添加到檔案中):
["Hello"]
["World"]
["One"]
["Two"]
uj5u.com熱心網友回復:
假設要洗掉的字符“[]”單獨出現在沒有任何其他前導/尾隨字符的行中(如提供的示例中所述),請您嘗試:
<command here> | sed -nE '/^\[]$/!p' | tee -a testFile
輸出:
["Hello"]
["World"]
["One"]
["Two"]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/458974.html
