[Gllug] sed question: hyperlinking URLs
Joel Bernstein
joel at fysh.org
Wed Jan 24 16:06:53 UTC 2007
On Wed, Jan 24, 2007 at 03:47:01PM +0000, J F wrote:
> I'm trying to write a sed command to pick out URLs in a file and turn them into an HTML hyperlink. I've come with this thus far:
Does it *have* to be sed? You can adapt the perl regex below to sed
format but it's nice to have a slightly terser format with character
class escapes.
Does this do what you need?
jbernstein at bandicoot 16:03 ~ $ cat /tmp/foo
Visit www.google.com.
foo www.foo.com
jbernstein at bandicoot 16:03 ~ $ perl -ple
's{(www\.[\w\d]+\.[\w\.]*\w)}{<a href="$1">$1</a>}g' /tmp/foo
Visit <a href="www.google.com">www.google.com</a>.
foo <a href="www.foo.com">www.foo.com</a>
I can't see anything wrong with that for what you requested.
I dare say somebody will manage to golf the regex down a little - the
key feature is the final \w (word character) to ensure you don't match
the trailing "."
/joel
-------------- next part --------------
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list