Convert URLs into HTML links using sed?

后端 未结 5 1369
一生所求
一生所求 2021-01-06 03:45

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 li

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-06 04:14

    This might work.

    sed -i -e "s|http[:]//[^ ]*|\0|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+)?|\0|g" yourfile.txt
    

    Those might get you started. I suggest leaving off the -i option to test your output before making the changes inline.

提交回复
热议问题