更换多行文字使用的sed? [英] Replace a word with multiple lines using sed?

查看:131
本文介绍了更换多行文字使用的sed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个bash脚本拥有以prepare一个E-邮件发送给用户。

I'm working on a bash-script that has to prepare an E-Mail for being sent to a user.

它聚集了一些数据,这些数据最终被东西多行。对于存储在 $ DATA

It aggregates some data, which ends up being multiple lines of stuff. For the example stored in $DATA.

现在,后位STFW我发现像 SED -ei的几件事S / _data _ / $ {数据} / Gmail.tpl 也< A HREF =htt​​p://stackoverflow.com/questions/6684487/sed-replace-with-variable-with-multiple-lines> SED可变换成多行的。他们没有工作。

Now, after a bit of stfw I found a few things like sed -ei "s/_data_/${DATA}/g" mail.tpl and also sed replace with variable with multiple lines. None of them work.

现在的问题是,如何获取 SED 来取代多行文本的东西吗?

Now the question is, how do I get sed to replace something with multiple lines of text?

(替代 SED 也欢迎!)

推荐答案

如果你用你的多行文本 \\ n S,这将用一个简单的工作 SED 命令:

If you build your multiple line text with "\n"s, this will work with a simple sed command as:

DATA=`echo ${DATA} | tr '\n' "\\n"`
#now, DATA="line1\nline2\nline3"
sed "s/_data_/${DATA}/" mail.tpl

这篇关于更换多行文字使用的sed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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