我正在研究一个bash脚本,它必须准备一封电子邮件发送给用户.
它汇总了一些数据,最终会产生多行内容.对于存储的示例$DATA.
现在,经过一些stfw我找到了一些类似的东西,sed -ei "s/_data_/${DATA}/g" mail.tpl并且还用多行替换变量.他们都没有工作.
现在问题是,如何sed用多行文本替换某些内容?
(sed也欢迎替代品!)
什么是mac shell脚本的sed命令将用myFile.txt的整个字符串内容替换字符串"fox"的所有迭代.
myFile.txt将是带有换行符和各种字符的html内容.一个例子是
</div>
</div>
<br>
<div id="container2">
<div class="question" onclick="javascript:show('answer2')";>
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑1
这是我的实际代码:
sed -i.bkp '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' $file
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到:
sed in place editing only works for regular files.
Run Code Online (Sandbox Code Playgroud)
在我的文件中,Q被大量的中文字符(!)取代.离奇!
我有一个从网上下载的多行字符串:
toast the lemonade
blend with the lemonade
add one tablespoon of the lemonade
grill the spring onions
add the lemonade
add the raisins to the saucepan
rinse the horseradish sauce
Run Code Online (Sandbox Code Playgroud)
我已将其分配给$INPUT,如下所示:
toast the lemonade
blend with the lemonade
add one tablespoon of the lemonade
grill the spring onions
add the lemonade
add the raisins to the saucepan
rinse the horseradish sauce
Run Code Online (Sandbox Code Playgroud)
此时,$INPUT已准备好替换到我的目标文件中,如下所示:
INPUT=$(lynx --dump 'http://example.net/recipes' \
| python -m json.tool \
| awk '/steps/,/]/' \ …Run Code Online (Sandbox Code Playgroud)