使用 sed 将 URL 转换为 HTML 链接? [英] Convert URLs into HTML links using sed?

查看:14
本文介绍了使用 sed 将 URL 转换为 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=""></a>|g" yourfile.txt

这取决于网址后跟一个空格(并非总是如此).

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:"></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 将 URL 转换为 HTML 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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