Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing or replacing IP address from text field 1

Status
Not open for further replies.

smmedeiros

Technical User
Feb 21, 2008
74
0
0
US
Has anyone been successful with removing an IP address from a text field of varying size with the IP address itself being of varying formats
For example.
line1
line2
some type of text information 11.1.111.1
line3
line4

desired output
line1
line2
some type of text information xx.x.xxx.x
line3
line4

Sample2
I want to replace 1.123.45.5 with a bunch of x values

desired output
I want to replace x.xxx.xx.x with a bunch of x values


the IP address shows up with varying length and in different / non-consistent sections of the text field.

appreciate anyone's ideas
basically looking to redact all IP addresses by either removing all together are replacing with 'xxxx' values.


 
Are there other numbers in the text? You could potentially just search for numbers and replace them with 'x'.

stringvar z := {table.textfield};
stringvar y;
numbervar i;
numbervar j := len(z);

for i := 1 to j do(
if isnumeric(z) then
y := y + 'x' else
y := y + z
);
y

-LB
 
Thank you lbass for the idea. To answer your question, yes, more often than not there will be other numeric values in the field.
 
Well, then how would the IP address differ from those numbers. Will the other numbers have "." in them? Is there some other way the IP addresses would always differ from other numbers in the text? Would the fact that the IP addresses have several "."'s distinguish them from the other numbers?

-LB
 
lbass - yes, an IP address will allows contain multiple "." whereas any other numeric value may contain a single 'dot' such as dollar amount or perhaps end of sentence
ie - $1500.37 or "My account balance is 197.60." (not allows in proper $ format)

yes - my data is ugly!

 
Try this--it worked here:

stringvar z := {table.textfield};
stringvar array a := split({table.textfield}," ");
numbervar b;
stringvar y :="";
numbervar i;
numbervar j := len(z);

for b := 1 to ubound(a) do(
for i := 1 to j do(
if ubound(split(a,"."))>3 and
isnumeric(a) then
y := y + 'x' else
y := y + a + (if i=j then " ")
));
y

-LB
 
LBASS
OMG. THANK YOU..THANK YOU..THANK YOU.
You’re a GENIOUS!
working as suggested above.
You have saved me hours’ worth of manual data scrubbing!

HUGE “Thank You”!

 
LB -
I ran your suggestion in a small sampling and it was perfect.
Running it against my full collection of ticket extracts, I'm running into this error "A loop was evaluated more than the maximum number of times allowed"
Any suggestions?
 
How many characters can one instance of the field have?

-LB
 
I think I originally misread your question. The field has a limit of 4000 characters. Within the field, this IP address I'm trying to redact can be multiple showings. I've seen up to 8 occurrences so far.
I wasn't sure if it's the loop within the field itself or the volume of the data I was pulling in. YTD ticket information. I've tried to extract a single week's worth of data, and still no such luck.
 
I was asking about the number of characters in the entire field, not the number of IP addresses in the field and not the number of characters in the IP Address. But anyway...

You can try the two formulas below. Not sure which will be best.

//Formula2:
local stringvar array a := split({table.textfield}," ");
local numbervar b;
local stringvar y := "";

for b := 1 to ubound(a) do(
if ubound(split(a,"."))>3 then
y := y + replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(a,chr(48),"x"),chr(49),"x"),chr(50),"x"),chr(51),"x"),chr(52),"x"),chr(53),"x"),chr(54),"x"),chr(55),"x"),chr(56),"x"), chr(57),"x")+" "
else y := y + a+" "
);
y

//Formula3:
local stringvar array a := split({table.textfield}," ");
local numbervar b;
local stringvar y := "";
local numbervar i;
local stringvar x := "";

for b := 1 to ubound(a) do(
if ubound(split(a,"."))>3 then(
for i := 1 to len(a) do(
if isnumeric(a) then
y := y + "x" else
y := y + a
));
if ubound(split(a,"."))>3 then
x := x + y + " " else
x := x + a+" "
);
x

-LB
 
Formula 2 is working! Thank you for all the guidance and instructions.
Have a great holiday weekend! (I know I can now that I can deliver my reports!) :)

Appreciate all the guidance and patience.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top