Archive
Highlighted

How can I remove additional field values?

Path Finder

I've tried several different ways to resolve this issue including using 'rex' and 'replace' but I can't seem to get it to work.

The dst field on log results comes out as "192.168.1.1:1234:ABCD-A123"

How can I just get the IP "192.168.1.1" and remove the other data?

Thanks!

0 Karma
Highlighted

Re: How can I remove additional field values?

SplunkTrust
SplunkTrust

Are you trying to replace it at search time or index time?

This will remove it at search time
| rex mode=sed s/\d+\.\d+\.\d+\.\d+\S+/\d+\.\d+\.\d+\.\d+/g

This will remove it at index time
SEDCMD-remove = ...

View solution in original post

Highlighted

Re: How can I remove additional field values?

Path Finder

This worked, thanks! And it was at search time.

One additional question I failed to mention. How can I pass this removal to the additional part of my search below? This removal doesn't appear to change the 'dst' field value with the list command piece, if that makes sense.

| stats count by dst, src | stats list(src), list(dst) by count

Thanks!

0 Karma
Highlighted

Re: How can I remove additional field values?

Builder

Use this search

Your search | rex field=dst "(?P\d{0,3}.\d{0,3}.\d{0,3}.\d{0,3}):" | stats count by IP_Only

0 Karma
Highlighted

Re: How can I remove additional field values?

Path Finder

It's giving me an error message:
Error in 'rex' command: Encountered the following error while compiling the regex '(?P\d{0,3}.\d{0,3}.\d{0,3}.\d{0,3}):': Regex: unrecognized character after (?P

Thanks!

0 Karma
Highlighted

Re: How can I remove additional field values?

SplunkTrust
SplunkTrust

So what this is doing is it's finding a pattern and replacing it with just the IP. The rex mode=sed works like this

s/<Regex to find pattern>/<-Replace it with this pattern---->/g

So if you want to apply this to your dest field, you would have to pattern match it like the regex above. Or you can simply extract the the IP from that field and create a new field with it. Paste the pattern of your dest IP and source IP so I can see how they differ

0 Karma
Highlighted

Re: How can I remove additional field values?

Path Finder

Okay, that make sense, thanks!

I'll mess around with it and should be able to come up with what I need based on the information you gave me.

Thanks!

Highlighted

Re: How can I remove additional field values?

SplunkTrust
SplunkTrust

Don't forget to accept the answer when this solves your problem!

0 Karma
Highlighted

Re: How can I remove additional field values?

Builder

Use this REX to extract only IP from it.

| rex field=_raw "(?P\d{0,3}.\d{0,3}.\d{0,3}.\d{0,3}):"

Thanks

0 Karma