我正在尝试替换当前输出为
http://domain1.com/subfolder1/http://domain2.com/subfolder2
这样它就只能输出为
http://domain2.com/subfolder2
我正在使用SED替换一个URL与后一个域名,但我无法使它工作。如果我将"domain1“设置为"domain2”,那么它可以工作,但是我希望能够替换整个字符串。
我正在尝试这样做,下面的代码如下:
for FILE in `cat/WORKDIR/$inputControlFileName`; do sed -i -e "s~$SEARCHTEXT~$REPLACEWITH~g" $OutputDirectory/$FILE; done;
我的搜索参数是http://domain1.com/subdomain/http://domain2.com/subdomain
,替换参数是http://domain2.com/subdomain
感谢你的指导。
感谢大家的帮助,最后我只输出domain1.com/domain.2.com,然后转义存储在变量中的值。
发布于 2019-08-23 13:07:03
尝尝这个,
echo "http://domain1.com/subfolder1/http://domain2.com/subfolder2" | sed 's/^http.*http:/http:/'
http://domain2.com/subfolder2
发布于 2019-08-23 13:30:47
如果您在URI中从不有:,则只能使用builtins进行此操作。
function last_addr(){
IFS=:
string="$1"
array=($string)
echo -n http:; echo ${array[-1]}; unset IFS
}
last_addr 'http://domain1.com/subfolder1/http://domain2.com/subfolder2'
https://unix.stackexchange.com/questions/537037
复制相似问题