How to find replace last digit of IP address

How to find replace last digit of IP address

3
NewbieNewbie
3

    Dec 22, 2004#1

    I have IP's in an IIS6 XML format metabase that I want to search for the regular expression 10.198.68.??3 and replace it with that same thing only changing the very last 3 to a 2. Thus the following should replace:
    10.198.68.153 --> 10.198.68.152
    10.198.68.73 --> 10.198.68.72
    10.198.68.3 --> 10.198.68.2

    Any advice is appreciated!

    206
    MasterMaster
    206

      Dec 22, 2004#2

      Try this macro:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Top
      Find RegExp "(10[.]198[.]68[.])3(\D)"
      Replace All "\12\2"
      Top
      Find RegExp "(10[.]198[.]68[.])([0-9]*)3(\D)"
      Replace All "\1\22\3"
      Top
      Find RegExp "(10[.]198[.]68[.])([0-9]*)([0-9]*)3"
      Replace All "\1\2\32"
      Software For Metalworking
      http://closetolerancesoftware.com

      16
      Basic UserBasic User
      16

        Dec 23, 2004#3

        I'm not sure that last find is correct, I think it could do the wrong thing on some inputs, e.g. 10.198.68.33, 10.198.68.333, 10.198.68.343 or 10.198.68.533

        I think it should be:

        Find RegExp "(10[.]198[.]68[.])([0-9]+)([0-9]+)3"

        (+ instead of * so they can't match zero characters)

        but I'm having difficulty testing it because the macro is crashing UE on some inputs. e.g. a file containing these lines:

        10.198.68.153
        10.198.68.73
        10.198.68.3
        10.198.68.33
        10.198.68.32
        10.198.68.23
        10.198.68.333
        10.198.68.332
        10.198.68.323
        10.198.68.322
        10.198.68.233
        10.198.68.232
        10.198.68.223
        10.198.68.223
        10.198.68.222
        10.198.68.22
        10.198.68.2
        10.198.68.343
        10.198.68.533

        (note file ends with a line return. The last entry will not match the first two finds in the macro otherwise)

        It appears to be caused by 10.198.68.333 or 10.198.68.332 (both must be followed by another character)

        206
        MasterMaster
        206

          Dec 23, 2004#4

          Sam,

          That's something - I've never had a macro doing nothing more than search/replace result in crashing UE before.

          I tried to test your suggestion about substituting a + for the *, and used one of your strings 10.198.68.533 to replace the first line in my original test file.

          CRASH!!

          I'm emailing this thread to IDM.


          Mike
          Software For Metalworking
          http://closetolerancesoftware.com

          1
          NewbieNewbie
          1

            Dec 30, 2004#5

            Search and replace using (UE style) Regular Expressions

            Find What: ^(10.198.68.[0-9]++^)3
            Replace With: ^12

            I tested against Sam's test lines. No problem.

            3
            NewbieNewbie
            3

              Jan 03, 2005#6

              I tried jpax's simpler find replace but i got 'search string not found' error. To be more specific I'm attempting to parse a Win2003 IIS6 metabase.xml file and replace all th IPs last number from 2 --> 3 in an effort to add a third server to our web farm. The IP 10.198.68.XX3 is followed by :80: & :443: for http & https so the find replace will be working on a lines that looks exactly like this:

              SecureBindings="10.198.68.153:443:"
              ServerBindings="10.198.68.153:80:"

              which should find/replace to:

              SecureBindings="10.198.68.152:443:"
              ServerBindings="10.198.68.152:80:"

              Any advince is appreciated!

              206
              MasterMaster
              206

                Jan 03, 2005#7

                Unix regular expression mode
                regular expressions checked
                cursor at top of file


                Find What: 3([:]\d*[:]["])$
                Replace With: 2\1
                Software For Metalworking
                http://closetolerancesoftware.com