Splunk Search

Extracting each value from a multi-valued field

smhsplunk
Communicator

I have a column with some information as follows

traffic_location
ABC 23 EFG RKY
ABC 12 HIJ 23
ABD 23 HIJ 12

ABD 12 KYP 23
ABC 12 RMP 11

This is a single column, the values inside this single column is separated by single spaces.
I would like to access each of the 4 parts to put it in a dropdown menu, hence I need to access
them individually, The values also have many duplicates, so I also want to remove the duplicate.
So far I have this, but its returning me the entire row

source=traffic_information | search * traffic_location | fields traffic_location | dedup traffic_location | eval firstValue=split(traffic_location," ") | search firstValue=1

The other I tried is this

source=traffic_information | search * traffic_location | fields traffic_location | dedup traffic_location | rex "^(?<traffic_location>\w+)" | table traffic_location

But I am getting the entire column and not sure how to get the split parts, can we get eval from rex ?

Please help.

Thanks in Advance.

0 Karma
1 Solution

javiergn
Super Champion

If you know the order of your fields is always the same you could do this:

 source=traffic_information 
| search * traffic_location 
| fields traffic_location 
| dedup traffic_location 
| eval traffic_location=split(traffic_location," ") 
| eval field1 = mvindex(traffic_location, 0)
| eval field2 = mvindex(traffic_location, 1)
| eval field3 = mvindex(traffic_location, 2)
| eval field4 = mvindex(traffic_location, 3)

View solution in original post

sundareshr
Legend

You have couple of options

REX command

source=traffic_information traffic_location=* | rex field=traffic_location "(?<f1>[^\s]+)\s(?<f2>[^\s]+)\s(?<f3>[^\s]+)\s(?<f4>[^\s]+))"

Split command

source=traffic_information traffic_location=* | eval temp=split(traffic_location ," ") | eval f1=mvindex(temp,0)| eval f2=mvindex(temp,1)| eval f3=mvindex(temp,2) | eval f4=mvindex(temp,4)  | fields - temp

javiergn
Super Champion

If you know the order of your fields is always the same you could do this:

 source=traffic_information 
| search * traffic_location 
| fields traffic_location 
| dedup traffic_location 
| eval traffic_location=split(traffic_location," ") 
| eval field1 = mvindex(traffic_location, 0)
| eval field2 = mvindex(traffic_location, 1)
| eval field3 = mvindex(traffic_location, 2)
| eval field4 = mvindex(traffic_location, 3)

smhsplunk
Communicator

Thanks! This is what I was looking for.

0 Karma
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!

Get Agentic with Splunk Lantern: Connect to Cisco Cloud Control, Transform ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

July Community Events: Master ITSI 5.0 & Automate Splunk

Struggling with alert fatigue or feeling like you're spending more time on infrastructure maintenance than ...

New Release of Federated Search: Bringing Splunk Analytics to More of Your Data

Organizations today are generating more data than ever and storing it across cloud object stores, data lakes, ...