Bash 替换url中的所有域名

Bash 替换url中的所有域名,bash,sed,replace,Bash,Sed,Replace,假设我有这样一个站点地图文件: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://www.sampledomain.com/foo.html</loc> <changefreq>weekly</changefreq> <priority>0.7</p

假设我有这样一个站点地图文件:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
       <loc>https://www.sampledomain.com/foo.html</loc>
       <changefreq>weekly</changefreq>
       <priority>0.7</priority>
    </url>
    <url>
       <loc>https://www.anotherdomain.nl/hello.html</loc>
       <changefreq>weekly</changefreq>
       <priority>0.3</priority>
    </url>
    ...
</urlset>

https://www.sampledomain.com/foo.html
每周的
0.7
https://www.anotherdomain.nl/hello.html
每周的
0.3
...
我想将所有URL(不是硬编码到www.sampledomain.com和www.anotherdomain.nl)替换为www.mynewwebsite.org,而不更改文件夹/页面路径

这可以使用bash吗

编辑: 期望输出:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
       <loc>https://www.mynewwebsite.org/foo.html</loc>
       <changefreq>weekly</changefreq>
       <priority>0.7</priority>
    </url>
    <url>
       <loc>https://www.mynewwebsite.org/hello.html</loc>
       <changefreq>weekly</changefreq>
       <priority>0.3</priority>
    </url>
    ...
</urlset>

https://www.mynewwebsite.org/foo.html
每周的
0.7
https://www.mynewwebsite.org/hello.html
每周的
0.3
...

以下sed命令仅在
标记内应用替换:

sed 's@<loc>.*www.\w*\.\w*/@<loc>https://www.mynewwebsite.org/@' inputfile

你能给出一个输入和期望输出的例子吗?谢谢你的回答,但这不是我想要的(也不是我问的)。我已经用所需的输出更新了我的问题。我正在尝试,但它没有给出所需的输出。这不会产生所需的输出,也不会试图解决问题的意图(只需更改任何“.html”文件的域名,并保留下面的“.html”文件名即可),然而,这是一个被接受的答案,并且有多张赞成票。如图所示……我还测试了它,它不仅没有产生预期的输出,而且根本无法产生预期的输出,因为它将替换每个URL,包括
https://www.anotherdomain.nl/hello.html
,带有
https://www.mynewwebsite.org/foo.html
(注意从“hello.html”到“foo.html”的更改)。再次测试它,这次运行“diff”,而不仅仅是目视检查预期输出与实际输出。@xDantehh请查看更正的命令。根据Ed Morton的评论,作为答案接受的命令是不正确的,所以我更正了它,现在它给出了所需的输出。
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">                             
    <url>                                                                
       <loc>https://www.mynewwebsite.org/foo.html</loc>                           
       <changefreq>weekly</changefreq>                                   
       <priority>0.7</priority>                                          
    </url>                                                               
    <url>                                                                
       <loc>https://www.mynewwebsite.org/hello.html</loc>   
       <changefreq>weekly</changefreq>
       <priority>0.3</priority>
    </url>
    ...
</urlset>