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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...