【发布时间】:2016-10-21 12:32:49
【问题描述】:
我有两个变量,
first= new pool ser/@10.25.89.322
second=ESX_10.2.3.4@10.52.33.21
我想用新池 ser/@10.25.89.322 替换 ESX_10.2.3.4@10.52.33.21 并且还想删除新单词前的空格。
我试过了,
sed -i -e "s/${second}/"${first//\\/\\\\}"/g"
和
sed -i -e "s/${second}/"${first//\\[ ]*/\\\\}"/g"
sed -i -e "s/${second}/"${first//\\ */ *\\\\}"/g"
我不想删除空格,只想按原样替换(“new”之前的空格除外)。
【问题讨论】:
-
我喜欢 ,sed -i -e "s/${second}/"${first//\\/\\\\}"/g" 和 sed -i -e "s/${second}/"${first//\[ ]*/\\\\}"/g" 也 sed -i -e "s/${second}/"${first//\\ */ *\\\\}"/g" 但没用。