Splunk Search

How to add a character to front of result if true in an if statement?

alex389
Engager

Hi, I want to use an eval if statement to add a minus onto the original value if it's is true. I am using table command to display these results.

Value0 = 10
Value1 = No

In the above scenario I want Value0 to to become -10

What I have so far only replaces Value0 with "-" only and does not retain the original Value0. What is the correct way to do this

Search | eval Value0=if(Value1="No", "-" ,Value0)

Thank you

0 Karma
1 Solution

renjith_nair
Legend

@alex389,

eval Value0=if(Value1=="No",-1*Value0,Value0)
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

renjith_nair
Legend

@alex389,

eval Value0=if(Value1=="No",-1*Value0,Value0)
---
What goes around comes around. If it helps, hit it with Karma 🙂

renjith_nair
Legend

Just in case if you need a '-' character for non integer field then, "." is the concatenation operator.

eval Value0=if(Value1=="No","-".Value0,Value0)
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...