sed append to string | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

sed append to string

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-13-2010
numele numele is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 4 September 2014, 3:12 PM 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 11-13-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 October 2014, 5:21 AM EDT
Location: France
Posts: 2,929
Thanks: 80
Thanked 624 Times in 596 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 11-13-2010
numele numele is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 4 September 2014, 3:12 PM EDT
Posts: 98
Thanks: 19
Thanked 0 Times in 0 Posts
Perfect! Thank you!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:16 AM.