How to use SED to find and replace URL strings with the "/" character in the targeted strings? [duplicate] How to use SED to find and replace URL strings with the "/" character in the targeted strings? [duplicate] bash bash

How to use SED to find and replace URL strings with the "/" character in the targeted strings? [duplicate]


/ is not the delimiter in sed commands, it's just one of the possible ones. For this example, you can for example use , instead since it does not conflict with your strings;

echo 'I think http://www.find.com/page is my favorite' |     sed 's,http://www.find.com/page,http://www.replace.com/page,g'


sed can take whatever follows the "s" as the separator. Since you are working with URL it is a good practice to use a different delimiter other than / to not confuse sed when your substitution ends and replacement begins.

However, having said that you can definitely use / if you wish too. You just need to escape the literal /.

So, you can either do:

sed 's/http:\/\/www.find.com\/page/http:\/\/www.replace.com\/page/g' input_file

or use a different delimiter to avoid making your cryptic sed more cryptic.

sed 's#http://www.find.com/page#http://www.replace.com/page#g' input_file