Splunk Search

How do you put a single row of key value pairs into one line from multiple rows?

lylereger
New Member

I have looked at various answers, but don't seem to be grasping what seems like it should be easy enough to do. Some help would be appreciated. Here is my set up.

I have data that comes back in a few simple fields(from JSON originally):

id      name      category     catval
123     bob       math         89
123     bob       English      76
123     bob       science      94
124     joe       math         79
124     joe       English      83
124     joe       science      91

And the output I am looking for is:

 id      name      math     English   science
123      bob       89       76        94
124      joe       79       83        91

Can anyone point me in the right direction here? If it helps, I do not have to dynamically determine the category field. I will know those values. I do need to grab them and get them sorted into single rows though.

Tags (1)
0 Karma

Vijeta
Influencer

Hi,

You can try something like below-

  <yourquery>|  eval id=id.",".name
    |chart sum(catval) as val over id by  catgory|  rex field=id "\w+,(?<name>\w+)"
| rex field=id "(?<id>\w+),"

|  table id name *
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...