使用sed将网址转换为HTML链接? [英] Convert URLs into HTML links using sed?
本文介绍了使用sed将网址转换为HTML链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可能(建议可能是更好的词)使用sed将URL转换为HTML超链接在文档中。因此,它会查找如下内容:
I'm wondering if it's possible (recommended might be the better word) to use sed to convert URLs into HTML hyperlinks in a document. Therefore, it would look for things like:
http://something.com
并替换为
<a href="http://something.com">http://something.com</a>
有任何想法吗?对于电子邮件地址也可以这样做吗?
Any thoughts? Could the same also be done for email addresses?
推荐答案
这可能有效。
sed -i -e "s|http[:]//[^ ]*|<a href=\"\0\">\0</a>|g" yourfile.txt
这取决于url后面跟着一个空格(并不总是这样)。
It depends on the url being followed by a space (which isn't always the case).
您可以使用类似的电子邮件。
You could do similar for e-mails with.
sed -i -e "s|\w+@\w+\.\w+(\.\w+)?|<a href=\"mailto:\0\">\0</a>|g" yourfile.txt
我建议在进行内联更改之前不要使用-i选项来测试输出。
Those might get you started. I suggest leaving off the -i option to test your output before making the changes inline.
这篇关于使用sed将网址转换为HTML链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文