[Gllug] sed question: hyperlinking URLs
Nix
nix at esperi.org.uk
Wed Jan 24 22:22:46 UTC 2007
On 24 Jan 2007, J. F. spake thusly:
> 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:
>
> sed -e "s/\(www\.[,\=\/\%\&\+\#\?0-9_a-z\.A-Z-]\+\)/\x3Ca href=\"http\x3A\/\/\1\"\x3E\1\x3C\/a\x3E/g" file.txt
>
> (\x3C is a '<' character; \x3E is a '>' character; \x3A is a colon.)
>
> The trouble is, the input text contains URLs at the end of sentences and the expression picks up the full stop ending the sentence.
You need negative lookahead assertions to do this. sed doesn't have
them, nor does awk :/
--
`The serial comma, however, is correct and proper, and abandoning it will
surely lead to chaos, anarchy, rioting in the streets, the Terrorists
taking over, and possibly the complete collapse of Human Civilization.'
-------------- 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