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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 26-07-2011 11:22am
    #1
    Registered Users, Registered Users 2 Posts: 5,708 ✭✭✭


    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,602 ✭✭✭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,602 ✭✭✭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