Getting Data In

How to create a table from key value pairs which are not always present?

MarietaO
Engager

Hi everyone,

I would like to extract a table. For instance:

SOH is a special character

Input

id=1, message body= [35=DSOH45=CSOH]

id= 2, message body= [35=FSOH53=ASOH45=CSOH]

+10k messages as such

Result

35  45 53

D    C    

F     C   A

 

Create headers with all keys provided through all messages.

If key is not provided on message then cell should be empty.

As you can see 53 is not always present, when that is the case its cell is empty.

 

Thanks in advance.

 

Labels (1)
Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| transpose 0 header_field=key column_name=key
| sort 0 key
| transpose 0 header_field=key column_name=key
| fields - key

View solution in original post

0 Karma

MarietaO
Engager

Works, thanks a lot. And if I want to short by numeric values the columns e.g. asc.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Can you give an example of what you have and what you would like it to be?

0 Karma

MarietaO
Engager

Sure, thanks a lot.

k1=1, k2=3,body=[8=FIX.4.19=9035=049=INVMGR56=BRKR]

k1=1, k2=3, body=[8=FIX.4.11=1035=049=INVMGR58=BR]

many key value pairs in body (not known).

order is numeric on columns.

To export to csv as a table.

1935495658
 900INVMGRBRKR 
10 0INVMGR BR
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| transpose 0 header_field=key column_name=key
| sort 0 key
| transpose 0 header_field=key column_name=key
| fields - key
0 Karma

MarietaO
Engager

works perfectly thanks.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "35=(?<f35>\w+)SOH"
| rex "45=(?<f45>\w+)SOH"
| rex "53=(?<f53>\w+)SOH"
0 Karma

MarietaO
Engager

e.g. 8=FIX.4.19=9035=049=INVMGR56=BRKR

0 Karma

MarietaO
Engager

The contents of the body field are not indexed. SOH is an invisible character in ASCII.

SOH

The unique keys  are unknown.

Body is indexed but not the key value pairs that I would like to transform to a table.

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex max_match=0 "(?<_name>\d+)=(?<_value>\w+)\cA"
| eval namevalue=mvzip(_name, _value)
| mvexpand namevalue
| eval _name=mvindex(split(namevalue,","),0)
| eval _value=mvindex(split(namevalue,","),1)
| eval {_name}=_value
| fields - namevalue
| stats values(*) as * by _raw
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...