用 sed 将 old-link-url 替换为 new-link-url [英] replace old-link-url to new-link-url with sed

查看:35
本文介绍了用 sed 将 old-link-url 替换为 new-link-url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 bash 编写一个脚本,将 old-link-url 替换为 new-link-url我的问题是 sed 由于斜杠而无法替换 url.如果我只输入一些文字就可以了.

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.

我的代码

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

推荐答案

sed 支持 any 字符作为分隔符,因此如果您尝试替换的模式包含 /,使用不同的分隔符.最常用的是 #|

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

这篇关于用 sed 将 old-link-url 替换为 new-link-url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆