Splunk Search

How to dynamically create fields from unique values in a search?

wysmith
Engager

I have a table with users and various fields relating to each event. Here is an example:
user | City | State
user1 | SLO | CA
user1 | SLO | CA
user1 | LA | CA
user2 | PHX | AZ

I want to merge each the entries by user, and move the unique values in every field to new fields and have the values of the new fields be the ratio like so:
user | City-SLO | City-LA | City-PHX | State-CA | State-AZ
user1 | .66 | .33 | 0 | 1 | 0
user2 | 0 | 0 | 1 | 0 | 1

I tried to do this using the foreach command, but it didn't work as expected (the value 0 is put in just for experimenting and will be changed):

 ... | foreach * [eval <<FIELD>>-"<<FIELD>>"=0]

Is there a way to create new fields based on dynamic data?

Sorry about the poor description and the crude tables.

0 Karma

wysmith
Engager

I found the answer here: http://answers.splunk.com/answers/103700/how-do-i-create-a-field-whose-name-is-the-value-of-another-...

Apparently, it isn't documented, but you can use curly braces to get the value of the field. This is my final foreach query:
... | foreach * [eval <>-{<>}=<>]

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...