How to find replace last digit of IP address

Find, replace, find in files, replace in files, regular expressions

How to find replace last digit of IP address

Postby autobahn97 » Wed Dec 22, 2004 3:19 pm

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!
User avatar
autobahn97
Newbie
 
Posts: 3
Joined: Wed Dec 22, 2004 12:00 am

Re: How to find replace last digit of IP address

Postby mrainey56 » Wed Dec 22, 2004 4:52 pm

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"
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to find replace last digit of IP address

Postby SamHasler » Thu Dec 23, 2004 8:27 am

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)
User avatar
SamHasler
Basic User
Basic User
 
Posts: 16
Joined: Mon Aug 16, 2004 11:00 pm
Location: UK

Re: How to find replace last digit of IP address

Postby mrainey56 » Thu Dec 23, 2004 8:53 am

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
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to find replace last digit of IP address

Postby jpax » Thu Dec 30, 2004 3:10 pm

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.
User avatar
jpax
Newbie
 
Posts: 1
Joined: Thu Dec 30, 2004 12:00 am

Re: How to find replace last digit of IP address

Postby autobahn97 » Mon Jan 03, 2005 1:38 pm

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!
User avatar
autobahn97
Newbie
 
Posts: 3
Joined: Wed Dec 22, 2004 12:00 am

Re: How to find replace last digit of IP address

Postby mrainey56 » Mon Jan 03, 2005 3:15 pm

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


Find What: 3([:]\d*[:]["])$
Replace With: 2\1
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina


Return to Find/Replace/Regular Expressions