使用sed插入文件内容 [英] Using sed to insert file content
本文介绍了使用sed插入文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在给定模式之前插入文件内容
I'm trying to insert a file content before a given pattern
这是我的代码:
sed -i "" "/pattern/ {
i\
r $scriptPath/adapters/default/permissions.xml"
}" "$manifestFile"
它添加的是路径而不是文件的内容.
It adds the path instead of the content of the file.
有什么想法吗?
推荐答案
为了在模式之前插入文本,您需要在读入文件之前将模式空间交换到保持空间.例如:
In order to insert text before a pattern, you need to swap the pattern space into the hold space before reading in the file. For example:
sed "/pattern/ {
h
r $scriptPath/adapters/default/permissions.xml
g
N
}" "$manifestFile"
这篇关于使用sed插入文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文