replace old-link-url to new-link-url with sed

最后都变了- 提交于 2019-12-23 16:34:18

问题


I'm writing a script in bash that would replace old-link-url to new-link-url my problem is that sed can't replace the url because of the slashes. If i put just some text it works.

my code

sed -e s/"$old_link"/"$new_link"/g wget2.html > playlist.txt

回答1:


sed supports any character as separator, so if the pattern you are trying to replace contains /, use a different separator. Most commonly used are # and |

sed  's|foo|bar|g' input
sed  's#foo#bar#g' input



回答2:


Don't forget to put double quotes if you are using variables in sed substitution. Also, if your variable have / then use a different delimiter for sed. You can use _, %, |, # and many more.

So may be something like this would work -

sed -e "s_"$old_link"_"$new_link"_g" wget2.html > playlist.txt


来源:https://stackoverflow.com/questions/8544226/replace-old-link-url-to-new-link-url-with-sed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!