Splunk Search

convert table data to comma separated key value pair output

aniket
New Member

I am pretty new to splunk and i have a query which uses TABLE command to filter output on certain fields. The output looks like:

name           designation         salary

ABC             Manager               12345

XYZ             Clerk                         6789

 

I want to convert the output as:
name=ABC, designation=Manager, salary=12345
name=XYZ, designation=Clerk, salary=6789

Not sure how to transform the data. Can anyone help?

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

This is a more generic solution to the problem, using the foreach command. This will concatenate any set of fields into a new field called tmp. It won't guarantee any order though.

| makeresults 
| eval _raw="name           designation         salary
ABC             Manager               12345
XYZ             Clerk                         6789"
| multikv forceheader=1
| table name designation salary
| eval tmp=""
| foreach * [ eval tmp=if("<<MATCHSTR>>"="tmp", tmp, tmp.",<<MATCHSTR>>=".<<FIELD>>) ]
| eval tmp=substr(tmp,2)

 The last 3 lines do the work. 

0 Karma

renjith_nair
Legend

If its a definite set of fields , you can just concatenate them

|eval output="name=".name.",deignation=".designation.",salary=".salary|fields output

 

Run anywhere example

|makeresults|eval name="ABC XYZ"|makemv name|mvexpand name
|appendcols [|makeresults|eval designation="Manager Clerk"|makemv designation|mvexpand designation]
|appendcols [|makeresults|eval salary="12345 6789"|makemv salary|mvexpand salary]
|eval output="name=".name.",deignation=".designation.",salary=".salary|fields output
---
What goes around comes around. If it helps, hit it with Karma 🙂
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!

Guided Onboarding with Auto-schema Is Now Generally Available

  We are excited to announce the General Availability of Guided Onboarding with Auto-Schematization ...

ATTENTION: We’re Moving! (AGAIN!)

The Splunk Community Slack is undergoing a system migration to keep our workspace secure and ...

Deep Dive: Optimizing Telemetry Pipelines in Splunk Observability Cloud

In this session, we will peel back the layers of Splunk Observability Cloud’s cost-optimization features. ...