Splunk Search

Field data from fieldname in variable

auradk
Path Finder

Any way of achieving this:

| makeresults 
| eval Column1="MyData"
| eval TestField="Column1"
| eval Result{TestField}=if('{TestField}'="MyData",1,0)

The reason is simple. I want to define a lookup with all the fieldnames (columns) that is required for a specific category of events.
My current search is larger than this, but i have found this example to describe my problem the best. if i solve this i can solve the rest. The result should be that ResultColumn1 = 1

{TestField} works on the left side of = but not on the right side in the eval.
I tried every combination of TestField including (',",$,$$,<<) but i am not able to retrieve the data from the field which is defined in TestField.
If i use {TestField} on the right side of = i get an error. This is why i have put '{TestField}' in my example above.

I am using Enterprise 7.0.1

Any help is appreciated.

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

| makeresults 
 | eval Column1="MyData"
 | eval TestField="Column1"
 | eval Result{TestField}=""
 | foreach Result* [| eval "<<FIELD>>"=if('<<MATCHSTR>>'="MyData",1,0)]

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try

| makeresults 
 | eval Column1="MyData"
 | eval TestField="Column1"
 | eval Result{TestField}=""
 | foreach Result* [| eval "<<FIELD>>"=if('<<MATCHSTR>>'="MyData",1,0)]
0 Karma

auradk
Path Finder

Thank you so much - i battled with that all day 🙂
It worked like a charm and even made my other query more simpel.
I see now that i simply did not understand the documentation of foreach. Now i do.

0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...