Splunk Search

How to Combine 2 rows

minihyo
Engager

Hi,

 I'm new to Splunk. I expect to combine 2 rows like this but dont know how

COL1COL2VALUE
c1c2Amy
c2c1Bob
c3c4Carol
c4c3David

 

Expected answer

NEWC3VALUE
c1 / c2

Amy

Bob

c3 / c4

Carol

David

 

Thanks

Labels (3)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this run-anywhere example.

| makeresults 
| eval _raw="COL1	COL2	VALUE
c1	c2	Amy
c2	c1	Bob
c3	c4	Carol
c4	c3	David" 
| multikv forceheader=1
```Above just defines test data```
| eval COL3=mvappend(COL1, COL2)
| eval COL3=mvjoin(mvsort(COL3),",")
| stats values(VALUE) as VALUE by COL3
---
If this reply helps you, Karma would be appreciated.

gcusello
SplunkTrust
SplunkTrust

Hi @minihyo,

please, try something like this:

| makeresults
| eval _raw="COL1	COL2	VALUE
c1	c2	Amy
c2	c1	Bob
c3	c4	Carol
c4	c3	David"
| multikv forceheader=1
| eval ppp1=COL1.",".COL2, ppp2=COL2.",".COL1
| makemv delim="," ppp1
| makemv delim="," ppp2
| eval ppp1=mvsort(ppp1), ppp2=mvsort(ppp2)
| eval ppp=mvindex(ppp1,0)."/".mvindex(ppp1,1)
| stats values(VALUE) AS VALUE BY ppp

Ciao.

Giuseppe

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!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

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 ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...