Splunk Search

Dynamic variable fields generation

victorsalazar
Explorer

Hello Splunk Community

I would like to know if I can create a new column field from a multivalue field

MV field = 

1, 2, 3, 4 

then I have another MV field

a, b,c,d 

after that I want my search result to look like in the pictureq_splunk.png

Thanks in advance

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

mvzip the two mv fields together, mvexpand to split into multiple events, rex out the two values, eval a new field using one field value for the name and the other field for the value, then use stats to join the events back together

| streamstats count as event_no
| eval combined=mvzip(field1, field2)
| mvexpand combined
| rex field=combined "(?<key>[^,]*),(?<value>.*)"
| eval {key}=value
| stats values(*) as * by event_no

View solution in original post

victorsalazar
Explorer

Thanks a lot both answer solved my problem

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

mvzip the two mv fields together, mvexpand to split into multiple events, rex out the two values, eval a new field using one field value for the name and the other field for the value, then use stats to join the events back together

| streamstats count as event_no
| eval combined=mvzip(field1, field2)
| mvexpand combined
| rex field=combined "(?<key>[^,]*),(?<value>.*)"
| eval {key}=value
| stats values(*) as * by event_no

richgalloway
SplunkTrust
SplunkTrust

You already have two MV fields so it's not clear what field you want to create.

To produce the example output from the example inputs, try this query.

| makeresults | eval x="1,2,3,4", y="a,b,c,d" | eval x=split(x,","), y=split(y,",")
```The above just generates test data```
| eval z=mvzip(y,x)
| mvexpand z
| eval z=split(z,",") | eval h=mvindex(z,0), v=mvindex(z,1)
| fields h,v
| fields - _*
| transpose header_field=h
| fields - column
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...