Splunk Search

get the single value out of multiple

abhayneilam
Contributor

Hi,

I have the input like this :

Name Location


abhay kol,mumbai,kol
murari mumbai,chennai
trid delhi,delhi
xyz haridwar

My output should be like :

Name Location


abhay kol,mumbai
murari mumbai,chennai
trid delhi
xyz haridwar

If any double data is there in Location filed then it should be removed, I want to display only single value !!

Please help !!

Thanks
Abhay

0 Karma

sideview
SplunkTrust
SplunkTrust

You can do this by turning the Location into a multivalued field, and then using stats values to get only the distinct values for each Name.

<your search here> | eval Location=split(Location,",") | stats values(Location) as Location by Name

This makes a couple assumptions -- each Name value only appears in one row in your search results, and the comma character never makes an appearance in your actual Location values.

0 Karma

abhayneilam
Contributor

my input has some blank value also in the Location field:

Name Location


abhay kol,mumbai,kol
murari mumbai,chennai
trid delhi,delhi
xyz haridwar
abc
mno

my output should be like this :

Name Location
abhay kol,mumbai
murari mumbai,chennai
trid delhi
xyz haridwar
abc
mno

0 Karma

abhayneilam
Contributor

This is my search:

index="maa" | rex max_match=9999 field="Location" (?(?i)"(delhi|mumbai|kol|bu is)")|eval final=mvjoin(ONE,",")| table Name Age Location final | sort final + desc

0 Karma

bmacias84
Champion

Ok, another off the cuff search.


...| makemv delim="," Location | dedup Location | eval Location =mvjoin(Location ,",") | table Name, Location

or


...| makemv delim="," Location | dedup Location | eval Location=if(Name=Name,mvjoin(Location ,","),Location) | table Name, Location

0 Karma

kristian_kolb
Ultra Champion

Could you please also post

a) some sample events
b) the search that produces the first table

/k

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...