使用 sed 在第一次匹配后插入行 [英] Insert line after first match using sed
本文介绍了使用 sed 在第一次匹配后插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于某种原因,我似乎无法找到一个直接的答案,目前我的时间有点紧迫.我将如何使用 sed
命令在匹配特定字符串的第一行之后插入文本选择行.我有...
For some reason I can't seem to find a straightforward answer to this and I'm on a bit of a time crunch at the moment. How would I go about inserting a choice line of text after the first line matching a specific string using the sed
command. I have ...
CLIENTSCRIPT="foo"
CLIENTFILE="bar"
我想在 CLIENTSCRIPT=
行后插入一行,结果是 ...
And I want insert a line after the CLIENTSCRIPT=
line resulting in ...
CLIENTSCRIPT="foo"
CLIENTSCRIPT2="hello"
CLIENTFILE="bar"
推荐答案
尝试使用 GNU sed 执行此操作:
Try doing this using GNU sed:
sed '/CLIENTSCRIPT="foo"/a CLIENTSCRIPT2="hello"' file
如果您想替换就地,请使用
sed -i '/CLIENTSCRIPT="foo"/a CLIENTSCRIPT2="hello"' file
输出
CLIENTSCRIPT="foo"
CLIENTSCRIPT2="hello"
CLIENTFILE="bar"
文档
- 查看 sed doc 并搜索
\a
(追加) - see sed doc and search
\a
(append)
Doc
这篇关于使用 sed 在第一次匹配后插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文