UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 11th, 2006, 09:03 AM
techie_techie techie_techie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 techie_techie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 44 sec
Reputation Power: 0
Sed expression to look up and replace a string with speical condition

Hi,

I have the following xml string and using sed I need to replace the second myConnection's port value to something else. Ofcourse, I do not know that it is always 443..
<myConnection port="80"/>
<myConnection port="443"/>
<myConnection port="83"/>
<myConnection port="82"/>

The red marked string has to be replaced with new string.

TIA,
Sachin

Reply With Quote
  #2  
Old April 11th, 2006, 09:35 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
Try this:

Code:
sed -e '2s/\"[0-9]*\"/\"xxx\"/' file.txt

The important bit is the 2 just before the substitute command. Just replace xxx with the port it needs to be changed to.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sed expression to look up and replace a string with speical condition


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT