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

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...

Splunk Cloud Application Management in Terraform

Now On-Demand   We’re diving into how you can bring Infrastructure as Code (IaC) principles to your Splunk ...

What's New in Splunk Enterprise Security (ES) 8.6

Purpose-Built AI Agents for the Agentic SOC  Splunk Enterprise Security 8.6 expands AI in Security with ...