Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL replace with sed

Tags:

bash

sed

i want to change all links in html file using sed like this

s/ <a[^>]* href="[^"]*\// <a href="\http:\/\/www.someurl.com\//g

but it's not working.

My links:

<a href="http://www.mylink.com/help/rss.php" target="_top" title="RSS">RSS</a></div>

my script change only mylink.com/help/rss.php to someurl.com/help/rss.php

I need to change to only someurl.com

like image 326
w4h Avatar asked Nov 30 '25 17:11

w4h


1 Answers

Take out the space after the first slash, change all the sed slashes to another character such as | for readability and remove all the escaping from the URL slashes.

sed 's|<a[^>]* href="[^"]*/|<a href="http://www.someurl.com/|g'
like image 131
Dennis Williamson Avatar answered Dec 02 '25 08:12

Dennis Williamson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!