Insert content of file after first pattern match u

2019-09-02 07:47发布

问题:

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"

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?

回答1:

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

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


标签: bash shell sed