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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...