Boards.ie uses cookies. By continuing to browse this site you are agreeing to our use of cookies. Click here to find out more x
Post Reply  
 
Thread Tools Search this Thread
26-07-2011, 12:22   #1
veryangryman
Registered User
 
Join Date: Nov 2007
Location: Athlone
Posts: 2,773
Sed command to find and replace string with ip address+characters

Hi folks - hope you can help. I have this to replace any IP address with the word ThisIsATest in the file SiteBasic.xml


sed 's/[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/ThisIsATest/g' SiteBasic.xml

Works a charm

Problem is, i want it only to replace lines with this string

ossCorbaNameServer="1.2.3.4"/>

or in other words

ossCorbaNameServer="<ip address>"/>

All help much appreciated.

Last edited by veryangryman; 26-07-2011 at 12:30.
veryangryman is offline  
Advertisement
26-07-2011, 14:15   #2
daymobrew
Registered User
 
Join Date: Jul 2004
Location: Dublin 15
Posts: 4,835
Put that text into the regex and then put brackets around the pieces you want to keep and reference them in the 2nd half of the regex

For example:
's/\(keep=\)[0-9]\(other\)/\1ThisIsaTest\2/'
Should return:
keep=ThisIsaTestother

My escaping of chars is probably off but hopefully you get the idea.
daymobrew is offline  
27-07-2011, 09:31   #3
daymobrew
Registered User
 
Join Date: Jul 2004
Location: Dublin 15
Posts: 4,835
This might work:
Code:
sed 's/\(ossCorbaNameServer="\)[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}\("\/>\)/\1ThisIsATest\2/g' SiteBasic.xml
daymobrew is offline  
Post Reply

Quick Reply
Message:
Remove Text Formatting
Bold
Italic
Underline

Insert Image
Wrap [QUOTE] tags around selected text
 
Decrease Size
Increase Size
Please sign up or log in to join the discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search