使用sed将插入文件内容 [英] Using sed to insert file content
本文介绍了使用sed将插入文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图插入一个给定的模式之前,文件内容
I'm trying to insert a file content before a given pattern
下面是我的code:
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屋!
查看全文