使用sed在第一个模式匹配之后插入文件内容 [英] Insert content of file after first pattern match using sed

查看:60
本文介绍了使用sed在第一个模式匹配之后插入文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到"all.css"的第一个匹配项,并将文件内容插入到该匹配项下.我在bash脚本中使用的代码:

I need to find first occurrence of "all.css" and insert content of my file below this occurrence. Code that I use in my bash-script:

FILE="$OLD_WEB_SOURCES/logon.html"
BLA="$DIR/first_insert_android" 
sed '/all.css/ r $BLA' "$FILE" > TMP1
mv TMP1 "$FILE"

但是此代码对我不起作用.变量FILE和BLA的BTW echo 显示正确的路径.有人可以解释我在做什么错吗?

But this code doesnt work for me. BTW echo of variables FILE and BLA shows correct path. Can someone explain what I'm doing wrong?

推荐答案

您需要使用双引号(")来访问 sed .试试这个,

You need to use double quotes( " ) to access the shell variable( $BLA ) in sed. Try this,

sed "/all.css/ r $BLA" "$FILE" > TMP1

这篇关于使用sed在第一个模式匹配之后插入文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆