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

Get Updates on the Splunk Community!

New Year, New Changes for Splunk Certifications

As we embrace a new year, we’re making a small but important update to the Splunk Certification ...

[Puzzles] Solve, Learn, Repeat: Unmerging HTML Tables

[Puzzles] Solve, Learn, Repeat: Unmerging HTML TablesFor a previous puzzle, I needed some sample data, and ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...