Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

sed append to string

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-13-2010
numele numele is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 9 June 2015, 10:50 AM EDT
Posts: 98
Thanks: 19
Thanked 0 Times in 0 Posts
sed append to string

I am trying to replace in multiple files every instance of text that begins with http and add hyperlink characters to it. I can get it to work with the following:
Code:
sed -e "s/http*.*/<a href=\"&\">&<\/a>/g" *

as long as the http text is at the end of the file. I need it to stop at the end of the text which will end with a html, sh or cgi.

Example text file before:

Code:
If you wish to view your options, go to http://20.1.1.1/myoptions.cgi or go to http://10.1.1.1/nextoptions.sh

Example of after:

Code:
If you wish to view your options, go to <a href="http://20.1.1.1/myoptions.cgi">http://20.1.1.1/myoptions.cgi</a> or go to <a href="http://10.1.1.1/nextoptions.sh">http://10.1.1.1/nextoptions.sh</a> 

Sponsored Links
    #2  
Old Unix and Linux 11-13-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 7 April 2015, 6:37 PM EDT
Location: France
Posts: 2,931
Thanks: 81
Thanked 626 Times in 597 Posts

Code:
sed 's|http[^ ]*|<a href="&">&</a>|g' input


Code:
[ctsgnb@shell ~]$ echo "If you wish to view your options, go to http://20.1.1.1/myoptions.cgi or go to http://10.1.1.1/nextoptions.sh" | sed 's|http[^ ]*|<a href="&">&</a>|g'
If you wish to view your options, go to <a href="http://20.1.1.1/myoptions.cgi">http://20.1.1.1/myoptions.cgi</a> or go to <a href="http://10.1.1.1/nextoptions.sh">http://10.1.1.1/nextoptions.sh</a>
[ctsgnb@shell ~]$


Last edited by ctsgnb; 11-13-2010 at 05:56 PM..
The Following User Says Thank You to ctsgnb For This Useful Post:
numele (11-13-2010)
Sponsored Links
    #3  
Old Unix and Linux 11-13-2010
numele numele is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 9 June 2015, 10:50 AM EDT
Posts: 98
Thanks: 19
Thanked 0 Times in 0 Posts
Perfect! Thank you!
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I append a ^M to the end of each 129 character string Captain Shell Programming and Scripting 6 06-13-2009 01:13 AM
Append values before a string Nandagopal Shell Programming and Scripting 2 04-11-2009 06:04 AM
How can i append a file name with a string Nikhilindurkar UNIX for Dummies Questions & Answers 3 10-17-2008 07:16 AM
Search a string and append text after the string kesu2k Shell Programming and Scripting 8 07-18-2008 07:35 PM
append esc string beilstwh Shell Programming and Scripting 2 05-11-2005 01:33 PM



All times are GMT -4. The time now is 02:16 PM.