Splunk Search

How to combine field values?

Muthu_Vinith
Path Finder


Hi experts, I want to just combine these location sites - "HU1","IA2","IB0 and create new AM site.

I tried this query, it works but it shows only new site. How to see the all original sites along with the new site in location field?
|search location IN ("HU1","IA2","IB0")
|eval row=if(location IN ("HU1","IA2","IB0"),"AM",location)
|stats c by row.

How to solve any idea? 

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

When describing a problem, make sure to use consistent terms and explain new terms as you introduce them.  I assume that "original sites" means "HU1","IA2", and "IB0".  Is this correct?  The search logic seems opposite to what you are looking for.  Try this:

|search location IN ("HU1","IA2","IB0")
|eval row=if(location IN ("HU1","IA2","IB0"),location,"AM")
|stats c by row.

 

0 Karma

Muthu_Vinith
Path Finder

@yuanliu Let's assume for example in my data I'm having loction sites - AB,AC,AD,AF. I want new location that is AM. Where AM location should be the combination of (AB,AC,AD,AF)

Like this i need:

Muthu_Vinith_0-1705436049444.png

I tried this query as you mentioned earlier, but it doesn't work.

0 Karma

yuanliu
SplunkTrust
SplunkTrust

location that is AM. Where AM location should be the combination of (AB,AC,AD,AF)

Like this i need:

Muthu_Vinith_0-1705436049444.png


First, "the combination of (AB,AC,AD,AF)" is NOT "AM" in your illustration.  The illustration is the opposite of what you described. (Also, please use text table instead of screenshot.)

Second, for your initial question, I notice that you filter for "HU1","IA2","IB0".  Of course you will only get whatever definition you give for these three.  I think what you wanted is

 

``` |search location IN ("HU1","IA2","IB0")```
``` ^^^ no filtering ```
|eval row=if(location IN ("HU1","IA2","IB0"),location,"AM")
|stats c by row

 

But back to your new example.  Here is an emulation

 

| makeresults format=csv data="Location
AB
AC
AD
AE
AF
AG
AH"
``` data emulation above ```
| eval "New Location" = if(Location IN ("AB","AC","AD","AE","AF"),Location,"AM")

 

LocationNew Location
ABAB
ACAC
ADAD
AEAE
AFAF
AGAM
AHAM

Is this what you illustrated?

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...