我需要shell腳本來獲取文本文件中的隨機未知垃圾文本。我被困在如何做到這一點,因爲我不知道垃圾文本會說什麼。基本上我需要刪除之前,之後和之間的一切。我想保留片段內的文字。Shell腳本刪除字符串前後的文本
--Begin file
random unknown junk text
----Begin Piece one ----
random important text
----End Piece one ----
random unknown junk text
----Begin Piece two ----
random important text
----End Piece two ----
random unknown junk text
----Begin Piece two ----
random important text
----End Piece two ----
random unknown junk text
end of file
這可行,但如何將它保存到同一個輸入文件? – Matt
@Matt:'sed -n -i ...'(有些版本的'sed','-i'的備份擴展參數是強制的:'sed -n -i .bak ...')。你也可以執行'sed ... inputfile> temp && mv temp inputfile'。 –
真棒,這有效,謝謝你的幫助。這是我第一次使用sed。 – Matt