使用Sed替换网址中的所有basedomains

时间:2019-07-15 15:17:01

标签: sed

我必须用一个字符串替换可以是http / https / wss的url中的域名,而其余URL保持不变:

例如:

wss://mobile.site.com/long/url/other.php?id = blablah

wss://domainreplaced/long/url/other.php?id = blablah

它只能替代这些,而不会影响其他任何东西。

1 个答案:

答案 0 :(得分:0)

您将3个替换字符彼此相加,首先是http,然后是https,最后是wss,例如通过命令行/ shell上的管道:

以下适用于wss:

sed -e "s/wss:\/\/mobile.site.com/wss:\/\/domainreplaced/g"

要替换您给出的示例:

echo 'wss://mobile.site.com/long/url/other.php?id=blablah'|sed -e "s/wss:\/\/mobile.site.com/wss:\/\/domainreplaced/g"|sed -e "s/http:\/\/mobile.site.com/http:\/\/domainreplaced/g"|sed -e "s/https:\/\/mobile.site.com/https:\/\/domainreplaced/g"

它将保持其他协议不变,例如

echo 'ftp://mobile.site.com/long/url/other.php?id=blablah'|sed -e "s/wss:\/\/mobile.site.com/wss:\/\/domainreplaced/g"|sed -e "s/http:\/\/mobile.site.com/http:\/\/domainreplaced/g"|sed -e "s/https:\/\/mobile.site.com/https:\/\/domainreplaced/g"