更改包含多个' /'的字符串分隔符

时间:2017-05-29 12:58:14

标签: string unix sed

我有一个像string1="app/local/home/usr/data/"这样的字符串,我希望用string2="app2/local/home/blablabla"替换。如何将string1替换为string2?我尝试使用无效的sed

1 个答案:

答案 0 :(得分:0)

我认为这个脚本会为您提供最佳解决方案..

#!/bin/sh
string1="app/local/home/usr/data/";

text=$(dirname $(dirname $string1));
echo $text|sed "s/app/app2/"|
 sed -e "s/(.*\)/\1\/blahblah/"

这在执行script.sh

后给出输出
app2/local/home/blahblah