INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Removing or replacing IP address from text field

Removing or replacing IP address from text field

(OP)
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.


RE: Removing or replacing IP address from text field

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[i]) then
y := y + 'x' else
y := y + z[i]
);
y

-LB

RE: Removing or replacing IP address from text field

(OP)
Thank you lbass for the idea. To answer your question, yes, more often than not there will be other numeric values in the field.

RE: Removing or replacing IP address from text 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

RE: Removing or replacing IP address from text field

(OP)
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!

RE: Removing or replacing IP address from text field

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[b],"."))>3 and
isnumeric(a[b][i]) then
y := y + 'x' else
y := y + a[b][i] + (if i=j then " ")
));
y

-LB

RE: Removing or replacing IP address from text field

(OP)
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”!

RE: Removing or replacing IP address from text field

(OP)
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?

RE: Removing or replacing IP address from text field

How many characters can one instance of the field have?

-LB

RE: Removing or replacing IP address from text field

(OP)
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.

RE: Removing or replacing IP address from text field

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[b],"."))>3 then
y := y + replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(a[b],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[b]+" "
);
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[b],"."))>3 then(
for i := 1 to len(a[b]) do(
if isnumeric(a[b][i]) then
y := y + "x" else
y := y + a[b][i]
));
if ubound(split(a[b],"."))>3 then
x := x + y + " " else
x := x + a[b]+" "
);
x

-LB

RE: Removing or replacing IP address from text field

(OP)
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!) smile

Appreciate all the guidance and patience.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close