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!

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...