\begin{Jeff Waugh}
> I need to get the first URL found in a file or stdin. Much like urlview (man
> urlview for a regexp), but without all the UI guff. Think procmail...

sed -n 's%^.*\(\(\(\(\(ht\|f\)tp\)\|mailto\):\(//\)\?[^ >"]*\|www.[-a-z0-9.]+\)[^ 
.,;>">]\).*$%\1%p;t c;d;:c q'

or:

perl -ne 'if (m%((((ht|f)tp)|mailto):(//)?[^ >"]*|www.[-a-z0-9.]+)[^ .,;>">]%) {print 
$&; exit}'

which is actually shorter, and easier to read ..


if you're just looking for (ht|f)tp urls, the regex becomes quite a
bit simpler

-- 
 - Gus

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to