使用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