Help!
I am using sed to convert text files into easily viewed html tables.
I have managed all except converting the email addresses to mailto: links.
Multiple email addresses exist within the files, either preceded by a space or > (as part of HTML tag), and followed by either space or <
I've tried various things based around the below, but nothing seems to work.
sed -e "s|\w+@\w+\.\w+(\.\w+)?|<a href=\"mailto:\0\">\0</a>|g" nolinks.html > links.html
I am using super-sed 3.62 on an XP machine. (Sorry!!)
Can anyone please help?
Thanks
Nigel
Can you post sample email addresses and the required output format..?
Please wrap your sample files/lines within the CODE tag-icon available in the tool bar while posting reply.
Hi,
Thanks for your quick response.
mail addresses will be from domains such as domain.co.uk, domain.org.uk domain.com.
users could be name@ or firstname.lastname@. it is unlikely that anyone would have an apostrophe in the name.
For example: the text username@domain.org.uk would be converted to <A HREF="mailto:username@domain.org.uk">username@domain.org.uk</A> in the output file.
Nigel
Try..
echo 'username@domain.org.uk' | sed -n 's|[^ ]*@[^ ]*|<A HREF="mailto:&">&</A>|gp'
If the above did not help post few lines of your HTML file.
1 Like
Hi
Due to the limitations of the windows version needing double quotes I substituted:
echo username@domain.org.uk | sed -n "s|[^ ]*@[^ ]*|<A HREF=\"mailto:&\">&</A>|gp"
This returned sed: -e expression #1, char 30: unterminated `s' command
The working command I use to create hyperlinks is
sed -e "s|http[:]//[^<]*|<a href=\"\0\" style=\'text-decoration: none; color: blue; font-weight: bold;\'>\Details Here</a>|g" table.html > newtable.html
so I know that \" works within the command.
From a typical file:
<BR>For information contact
Emma on 01000 055530 / 0777777777 or emma@domain.org.uk</A><BR><BR>Choose
from
Thanks
Nigel
Sorted it!
I found the solution at launchpad.net:
adding the -r switch to my original code gave the working solution
Thanks for your time and help.
Nigel