我已经试过这无数的方法,时间认输,并要求主...sed的变量替换
#!/bin/bash
# Read in the VERSION.header file, this is a plain text file
# with returns, which in some of my tests, I am loosing the returns and getting
# one string wrapped only by the shell width
VERSION_HEADER=`cat VERSION.header`
sed 's/_VERSION_HEADER_/"$VERSION_HEADER"/g' DOCUMENTATION
字符串“_VERSION_HEADER_”作为文件文档线1当前存在。文件'VERSION.header'有大约18行。
我不会使用sed。我所要做的就是读取一个作为模板的文件,将该文件数据存储为变量,读入第二个文件,将其存储为变量。在第二个文件中查找标记,用第一个文件中的数据替换标记。
例子:
$猫VERSION.header
hi, this is my header file, how are you today
good, that is nice, great
have a nice day, k, thx, bye.
$猫文档
_VERSION_HEADER_
# This is a documentation file, please read it
# If you do not read it, you will get stuck to the toilet.
而且结果应该是:
嗨,这是我的头文件,你今天好吗
不错,那很好,很棒
祝你有美好的一天,k,thx,再见。
#这是一个文档文件,请阅读它
#如果你没有阅读它,你会被卡在厕所里。
你有什么结果? – hudolejev 2010-06-19 11:14:12
[用变量(sed)替换文本](http:// stackoverflow。com/questions/16297052/replace-a-text-with-a-variable-sed) – tripleee 2013-08-30 09:32:42