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