Splunk Search

Need help

teewenjie22
Engager

How to convert below 

_time    Server      col1     col2       col3

8am       SerA          1           2             3

9pm       SerA          5           6             7


into 

_time       Category          value        
8am           SerA_col1      1
8am           SerA_col2      2
8am           SerA_col3      3
9pm           SerB_col1      5
9pm           SerB_col2      6
9pm           SerB_col3      7

 

 

Labels (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@teewenjie22 

Try this. Update search as per your requirement. 

YOUR_SEARCH
| eval F="",V=""
| foreach col* [| eval F=if(F="","<<FIELD>>",F."|"."<<FIELD>>"), V=if(V="",'<<FIELD>>',V."|".'<<FIELD>>')]
| eval F=split(F,"|"),V=split(V,"|")
| eval t=mvzip(F,V) | fields - F V col*
| mvexpand t
| eval Category=Server."_".mvindex(split(t,","),0), value=mvindex(split(t,","),1) |fields time Category value

 

Sample:

| makeresults 
| eval _raw="time    Server      col1     col2       col3
8am       SerA          1           2             3
9pm       SerA          5           6             7" 
| multikv forceheader=1
| table time    Server      col1     col2       col3
| eval F="",V=""
| foreach col* [| eval F=if(F="","<<FIELD>>",F."|"."<<FIELD>>"), V=if(V="",'<<FIELD>>',V."|".'<<FIELD>>')]
| eval F=split(F,"|"),V=split(V,"|")
| eval t=mvzip(F,V) | fields - F V col*
| mvexpand t
| eval Category=Server."_".mvindex(split(t,","),0), value=mvindex(split(t,","),1) |fields time Category value

 

Thanks
KV
▄︻̷̿┻̿═━一

If this reply helps you, an upvote would be appreciated.

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...