Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

sed append to string

Shell Programming and Scripting


Closed    
 
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: 29 October 2016, 5:42 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 Unix and Linux 11-13-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 10 November 2016, 10:40 AM EST
Location: France
Posts: 2,948
Thanks: 82
Thanked 630 Times in 601 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 06: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: 29 October 2016, 5:42 PM EDT
Posts: 98
Thanks: 19
Thanked 0 Times in 0 Posts
Perfect! Thank you!
Sponsored Links
Closed

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 02:13 AM
Append values before a string Nandagopal Shell Programming and Scripting 2 04-11-2009 07:04 AM
How can i append a file name with a string Nikhilindurkar UNIX for Dummies Questions & Answers 3 10-17-2008 08:16 AM
Search a string and append text after the string kesu2k Shell Programming and Scripting 8 07-18-2008 08:35 PM
append esc string beilstwh Shell Programming and Scripting 2 05-11-2005 02:33 PM



All times are GMT -4. The time now is 03:40 AM.