Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Sed command to find and replace string with ip address+characters

Options
  • 26-07-2011 12:22pm
    #1
    Registered Users Posts: 5,580 ✭✭✭


    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.


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    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.


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    This might work:
    sed 's/\(ossCorbaNameServer="\)[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}\("\/>\)/\1ThisIsATest\2/g' SiteBasic.xml
    


Advertisement