Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 26-07-2011 12:22PM
    #1
    Registered Users, Registered Users 2 Posts: 5,761 ✭✭✭


    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, Registered Users 2 Posts: 6,677 ✭✭✭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, Registered Users 2 Posts: 6,677 ✭✭✭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