SED - Create mailto: link


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED - Create mailto: link
# 1  
Old 07-15-2011
SED - Create mailto: link

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
# 2  
Old 07-15-2011
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.
# 3  
Old 07-15-2011
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
# 4  
Old 07-15-2011
Try..
Code:
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.
This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 07-15-2011
Hi

Due to the limitations of the windows version needing double quotes I substituted:
Code:
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
Code:
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:

Code:
<BR>For information contact
   Emma on 01000 055530 / 0777777777 or emma@domain.org.uk</A><BR><BR>Choose
   from

Thanks
Nigel
# 6  
Old 07-21-2011
Sorted it!

I found the solution at launchpad.net:

Quote:
Supported for -r (extended regex) or -R (Perl-mode). NOTE: the -r
switch is an undocumented option in GNU sed v3.02+.
adding the -r switch to my original code gave the working solution

Thanks for your time and help.

Nigel
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

How to create a link that will display the contents of a PHP variable?

Greetings, I've wrote a script that when you point your browser to a machine it displays info about itself. Below is a small snippet of the script: <?php $iloipaddr = `ipmitool lan print | grep 'IP Address ' | cut -d\: -f2 | sed 's/ //'`; $sftwrlist = `rpm -qa | sort`; ?> <p><a... (9 Replies)
Discussion started by: crimso
9 Replies

2. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. UNIX for Advanced & Expert Users

Cannot create a link with the same name

Hi - Our system admin cannot create a link to NAS with one particular name but he can create with other names. What might be the cause? Regards ---------- Post updated at 11:30 AM ---------- Previous update was at 11:29 AM ---------- It says permission denied. (2 Replies)
Discussion started by: w020637
2 Replies

4. Solaris

Create a Link for a directory

Hi, I need to create a link as stagein01 for the /p11/prod/stagein01/. Please let me know the procedure for the same. Regards, VN (5 Replies)
Discussion started by: narayanv
5 Replies

5. Solaris

Not able to create a link in /etc/rc3.d in Solaris 10

HI I am using solaris 10.We are doing some failover testing and checking whether services are starting up when we reboot the server. As part of process i have moved scripts to /etc/init.d directory and trying to create a link /etc/rc3.d like this. But strangely it is giving an error... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

6. Solaris

Create sym-link into /dev (zone)

Hi i need to install a software into a zone, and this kind of software needs to have a file who is linked into /dev. But it is not possible to create a link into /dev nor create a file into it. -bash-3.00# ln -s /tmp/testfile /dev/ ln: cannot create /dev//testfile: Permission denied... (2 Replies)
Discussion started by: beta17
2 Replies

7. AIX

How to create a sym link pointing a changing name.

Hello A new file is created every day with the date appended to the end of a name. We are using Autosys to run jobs which watches for the file and runs jobs. But Autosys does not have the capability to figure out the current date. I tried creating a symlink like this ln -s... (1 Reply)
Discussion started by: vra5107
1 Replies

8. Shell Programming and Scripting

Shell script to create a link

Hi All, I have a problem to writing a shell script to create a soft link in some other directory For eg: /opt/Shreedhar/Naik is directory now i need to write shell script in the path /opt/Shreedhar/Naik which should create a soft link in /opt/Shreedhar. I have tried to write the script... (3 Replies)
Discussion started by: Shreedhar Naik
3 Replies

9. Shell Programming and Scripting

how to create symbolic link between folders.....

hi champs, i have folders structure up to log is there , which is as below, app | |---version-4.1 | |----bin | | | | | |-----a.sh | | |-----b.sh | | | |----log | | \---version (symbolic link to version-4.1) but i want to create another folder... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

10. UNIX for Dummies Questions & Answers

Create Symbolic Link

I am Solaris korn shell. I want to create a symbolic link. I have a directory /u01/ftp01/db I want to reference it as /u05/swe/my (this is not a real directory) I tried a symbolic link but it does not work ln -s /u01/ftp01/db /u05/swe/my ln: cannot create //u05/swe/my: No such... (2 Replies)
Discussion started by: lesstjm
2 Replies
Login or Register to Ask a Question