Splunk Search

Split pattern into multiple rows?

LearningGuy
Motivator

Split pattern in CSV lookup format into multiple rows
| lookup table.csv
Note that the number of SubnetID-IP pair is not always 4.   It could be from 1 to 4  or more (1...  N)
The example below is only one row, but the real data has multiple rows (eg. Comp-B to Comp-Z)

Before the split:       
Company        Location       SubnetID-IP
Comp-A           Loc- A           [{"subnet_id":"101","ip_address":"192.168.1.1"},{"subnet_id":"102","ip_address":"192.168.1.2"},{"subnet_id":"103","ip_address":"192.168.1.3"},{"subnet_id":"104","ip_address":"fd12:3456:789a:1::1"}]

After the split: 

Company        Location       IP                                subnetID
Comp-A            Loc-A            192.168.1.1                     101
Comp-A            Loc-A            192.168.1.2                     102
Comp-A            Loc-A            192.168.1.3                     103
Comp-A            Loc-A            fd12:3456:789a:1::1     104

Thank you so much for your help

Labels (3)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

spath is your fiend.

 

| spath input=Subnet-IP path={}
| mvexpand {}
| spath input={}

 

Your sample data gives

CompanyLocationip_addresssubnet_id{}
Comp-ALoc-A192.168.1.1101{"subnet_id":"101","ip_address":"192.168.1.1"}
Comp-ALoc-A192.168.1.2102{"subnet_id":"102","ip_address":"192.168.1.2"}
Comp-ALoc-A192.168.1.3103{"subnet_id":"103","ip_address":"192.168.1.3"}
Comp-ALoc-Afd12:3456:789a:1::1104{"subnet_id":"104","ip_address":"fd12:3456:789a:1::1"}

This is an emulation that you can play with and compare to your real data

 

| makeresults
| eval Company = "Comp-A", Location = "Loc-A", Subnet-IP = "[{\"subnet_id\":\"101\",\"ip_address\":\"192.168.1.1\"},{\"subnet_id\":\"102\",\"ip_address\":\"192.168.1.2\"},{\"subnet_id\":\"103\",\"ip_address\":\"192.168.1.3\"},{\"subnet_id\":\"104\",\"ip_address\":\"fd12:3456:789a:1::1\"}]"

 

View solution in original post

Tags (2)

LearningGuy
Motivator

Your first suggestion worked. Thank you so much

| spath input=Subnet-IP path={}
| mvexpand {}
| spath input={}

 
I ran your second suggestion and received this "Error in 'makeresults' command: This command must be the first command of a search."
What is the purpose of the following commands?
Note that my search is using | inputlookup test.csv. It looks like makeresults didn't work with inputlookup. Thank you

| makeresults
| eval Company = "Comp-A", Location = "Loc-A", Subnet-IP = "[{\"subnet_id\":\"101\",\"ip_address\":\"192.168.1.1\"},{\"subnet_id\":\"102\",\"ip_address\":\"192.168.1.2\"},{\"subnet_id\":\"103\",\"ip_address\":\"192.168.1.3\"},{\"subnet_id\":\"104\",\"ip_address\":\"fd12:3456:789a:1::1\"}]"

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

The makeresults block is meant to emulate inputlookup as a way of comparison in case the solution gives unexpected output.

yuanliu
SplunkTrust
SplunkTrust

spath is your fiend.

 

| spath input=Subnet-IP path={}
| mvexpand {}
| spath input={}

 

Your sample data gives

CompanyLocationip_addresssubnet_id{}
Comp-ALoc-A192.168.1.1101{"subnet_id":"101","ip_address":"192.168.1.1"}
Comp-ALoc-A192.168.1.2102{"subnet_id":"102","ip_address":"192.168.1.2"}
Comp-ALoc-A192.168.1.3103{"subnet_id":"103","ip_address":"192.168.1.3"}
Comp-ALoc-Afd12:3456:789a:1::1104{"subnet_id":"104","ip_address":"fd12:3456:789a:1::1"}

This is an emulation that you can play with and compare to your real data

 

| makeresults
| eval Company = "Comp-A", Location = "Loc-A", Subnet-IP = "[{\"subnet_id\":\"101\",\"ip_address\":\"192.168.1.1\"},{\"subnet_id\":\"102\",\"ip_address\":\"192.168.1.2\"},{\"subnet_id\":\"103\",\"ip_address\":\"192.168.1.3\"},{\"subnet_id\":\"104\",\"ip_address\":\"fd12:3456:789a:1::1\"}]"

 

Tags (2)
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...