Splunk Search

How to use a event value to create new field

jadengoho
Builder

I have a event that returns me this

alt text

what i want is to have a new field that will solve the equation
like
number |newfield | result
1 | 1+ 1 | 2

Tags (1)
0 Karma
1 Solution

niketn
Legend

@jadengoho, a command like the following will do the trick

 <YourBaseSearchwithSingleEvent>
| eval result=[| makeresults
| eval result=$newfield$
| return $result]

Following is a run anywhere example based on your sample data. PS: Since it uses map command it will have limit and performance issues based on number of sub searches:

| makeresults
| eval data="1,1+1;2,2+1;3,2+3*5;4,(2+(6*1))/2"
| makemv data delim=";"
| mvexpand data
| eval data=split(data,",")
| eval number=mvindex(data,0),newfield=mvindex(data,1)
| table number newfield
| map search="| makeresults
| eval result=[| makeresults
| eval result=$newfield$
| return $result]
| eval number=$number$,newfield=$newfield$"
| table number newfield result

alt text

Based on answer https://answers.splunk.com/answers/222544/eval-a-string-as-an-expression.html

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@jadengoho, a command like the following will do the trick

 <YourBaseSearchwithSingleEvent>
| eval result=[| makeresults
| eval result=$newfield$
| return $result]

Following is a run anywhere example based on your sample data. PS: Since it uses map command it will have limit and performance issues based on number of sub searches:

| makeresults
| eval data="1,1+1;2,2+1;3,2+3*5;4,(2+(6*1))/2"
| makemv data delim=";"
| mvexpand data
| eval data=split(data,",")
| eval number=mvindex(data,0),newfield=mvindex(data,1)
| table number newfield
| map search="| makeresults
| eval result=[| makeresults
| eval result=$newfield$
| return $result]
| eval number=$number$,newfield=$newfield$"
| table number newfield result

alt text

Based on answer https://answers.splunk.com/answers/222544/eval-a-string-as-an-expression.html

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...