我试图用属性文件中的值替换html文件中的[[****]]占位符。输入文件用SED替换占位符
示例内容:在财产文件
<html>
<host>[[my_host]]</host>
<port>[[my_port]]</port>
</html>
示例内容:
my_host=linkcmb.com
my_port=8080
我当前的脚本:
#/bin/sh
property_file=$1
input_html=$2
output_html=$3
IFS="="
while read k v || [[ -n "$k" ]]; do
test -z "$k" && continue
declare $k=$v
done <"$property_file"
eval "$(sed 's/\[\[\([^]]\+\)\]\]/${\1}/g' $input_html) >$output_html";
错误:HTML标签越来越评估过造成错误。
./some.sh: line 32: html: No such file or directory
./some.sh: line 33: host: No such file or directory
./some.sh: line 35: /host: No such file or directory
....
....
任何建议将不胜感激。谢谢。
附加样品输入线和输出预计为清楚......和sed是不是对HTML文件中使用适当的工具... – Sundeep
@Sundeep更新的问题,请检查 – popcoder
imo,这不适用于bash脚本和sed ...我没有使用正确的html解析器的经验......对于给定的示例,'sed -f <(sed's/^ \([^ =] * \)= \(。* \)/ s | \\ [\\ [\\ [\ 1 \\] \\] | \ 2 | /'property.txt)ip.html'可以工作,但它很容易打破真实使用案例 – Sundeep