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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...