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
Get Updates on the Splunk Community!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...