Splunk Search

Field extraction from data within backslashes

mbasharat
Builder

Hi,

I have dateset that contains IP addresses. IP Addresses are coming in variations due to ranges they are assigned to separated by \ backslashes. I need them to be extracted in multiple fields regardless of how many variations are there. See sample data below:

1.2.3.4\n4.5.6.7\n8.9.1.2
1.2.3.4\n4.5.6.7\n
1.2.3.4\n4.5.6.7
1.2.3.4\n4.5.6.7\n8.9.1.2

I need them like:
1.2.3.4\n4.5.6.7\n8.9.1.2
Value1: 1.2.3.4
Value2: 4.5.6.7
Value3: 8.9.1.2
Value4: and so on.....

So basically all values within backslash, I need them separated out in fields. Also, the letter "n" or any alphabets attached to any IP also needs to go.

Thanks in-advance!

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The IP addresses are not separated by backslashes, they're separated by newlines (\n). To split them up, use the split command followed by mvexpand. Assuming the addresses are in a field called 'foo', this should do it.

... | eval ips = split(foo, "\n") | mvexpand ips
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval _raw="1.2.3.4\n4.5.6.7\n8.9.1.2
1.2.3.4\n4.5.6.7\n
1.2.3.4\n4.5.6.7
1.2.3.4\n4.5.6.7\n8.9.1.2"
| multikv noheader=t 
| fields _*
| rename COMMENT as "this is sample, check this. from here, the logic"
| rex max_match=0 "(?<data>[\d.]+)"
| streamstats count as session
| mvexpand data
| streamstats count as cols by session
| eval cols="col".cols
| xyseries session cols data
0 Karma

mbasharat
Builder

Both yours and Rich's solutions work great but rich's solution is less typing :). Accepting Rich's and upvoting t04kawa! 🙂

Thank you both!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The IP addresses are not separated by backslashes, they're separated by newlines (\n). To split them up, use the split command followed by mvexpand. Assuming the addresses are in a field called 'foo', this should do it.

... | eval ips = split(foo, "\n") | mvexpand ips
---
If this reply helps you, Karma would be appreciated.
0 Karma

mbasharat
Builder

I used the same eval but with backslash only and it did not work and I have no idea why, added \n instead like yours and worked perfectly. THANKS!!

BTW, do you happen to know the reason why just backslash does not get picked up?

Both yours and @to4kawa solutions work great but rich's solution is less typing :). Accepting RIch's and upvoting t04kawa! 🙂

Thank you both!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Backslash by itself is not picked up because it is the escape character. That means it modifies the character that follows it. To match the literal backslash you must escape it \\\.

---
If this reply helps you, Karma would be appreciated.
0 Karma

mbasharat
Builder

Works. Thanks!!!

0 Karma

mbasharat
Builder

One more thing to add, below also worked:

| makemv delim="\n" IP_Extracted
| mvexpand IP_Extracted

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...