使用SED,我怎麼能插入(不能代替)的新行上爲每個文件關鍵字只有第一場比賽。
目前我有以下的,但這會插入每一行含有匹配關鍵字,我希望它只是插入新插入的行僅在文件中找到的第一個匹配:
sed -ie '/Matched Keyword/ i\New Inserted Line' *.*
例如:
myfile.txt文件:
Line 1
Line 2
Line 3
This line contains the Matched Keyword and other stuff
Line 4
This line contains the Matched Keyword and other stuff
Line 6
改爲:
Line 1
Line 2
Line 3
New Inserted Line
This line contains the Matched Keyword and other stuff
Line 4
This line contains the Matched Keyword and other stuff
Line 6
[這個問題](HTTP的可能重複://堆棧溢出。com/q/148451/1086804) - 您可以通過使用換行符和反向引用來適應它。另見[本sed指南](http://www.linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/sedfaq4_004.html) – 2012-04-02 02:18:13