Splunk Search

How do you swap key/value pairs for two-column data?

jturner900
Explorer

I'm trying to swap the roles of two columns. Normally, there is one "key" in the first column for every group of "values" in the second column. What if I want the values to become the keys? For instance, let's say the search "|index = dataname| table ColA, ColB" returns the following:

Col A Col B
John Seahawks, Lions, 49ers
Jason Titans, Seahawks, Dolphins
Rick Texans, Dolphins

I'd like the search redone. Should become

Col B Col A
Seahawks John, Jason
Lions John
49ers John
Titans Jason
Dolphins Jason, Rick
Texans Rick

Tags (4)
0 Karma

niketn
Legend

Splunk statistics commands like stats timechart can split data by the sequence of the field names. So in order to reverse the columns you can try the following two commands

index = dataname
| stats count by ColA ColB

index = dataname
| stats count by ColB ColA 
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...