Use the contents of a file to replace a string using SED

后端 未结 2 1584
小鲜肉
小鲜肉 2021-01-01 10:22

What would be the sed command for mac shell scripting that would replace all iterations of string \"fox\" with the entire string content of myFile.txt.

myFile.txt wo

2条回答
  •  时光说笑
    2021-01-01 10:28

    Ultimately what I went with which is a lot simpler than a lot of solutions I found online:

    str=xxxx
    sed -e "/$str/r FileB" -e "/$str/d" FileA
    

    Supports templating like so:

    str=xxxx
    sed -e "/$str/r $fileToInsert" -e "/$str/d" $fileToModify
    

提交回复
热议问题