【问题标题】:Change the string which has multiple '/' delimiters更改具有多个“/”分隔符的字符串
【发布时间】:2017-10-29 19:11:04
【问题描述】:

我有一个像string1="app/local/home/usr/data/" 这样的字符串,我想用string2="app2/local/home/blablabla" 替换它。如何将string1 替换为string2?我尝试使用sed,但没有成功。

【问题讨论】:

标签: string unix sed


【解决方案1】:

我认为这个脚本会给你最好的解决方案。

#!/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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多