Getting Data In

Condition

Khuzair81
Path Finder

c1 = US, c2 = UAE

L1 = English, L2 = Arabic

I want to get the answer in "ans" like, 

If c1= US, 

    then ans= L1

elseif c2 = UAE, 

     then ans= L2

 

 

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Splunk supports conditions using the if and case functions.  RTM at https://docs.splunk.com/Documentation/Splunk/8.2.0/SearchReference/ConditionalFunctions

Some examples, using a modification of the example logic (which will never execute the else clause):

| eval ans=if(c="US", "English","Arabic")

| eval ans=case(c="US", "English", c="UAE", "Arabic", 1==1, "Other")

| eval L1="English", L2="Arabic"
| eval ans=case(c="US", L1, c="UAE", L2, 1==1, "Other")
---
If this reply helps you, Karma would be appreciated.

Khuzair81
Path Finder
  1. @richgalloway

Please help in the below Query

c=US, UAE

Lang=English, Arabic

........... | rex fields=Lang "(? <myval>)" 

|  eval ans=case(c="US",myval)  | table ans, myval

I'm getting the 'ans' field as blank while 'myval' field has the Value.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Khuzair81 

Can you please try this?

YOUR_SEARCH
| eval c=split(c,","), Lang=split(Lang,",")
| eval Ans = mvindex(Lang,mvfind(c,"US"))
| table Ans

 

Here "US" is the value what I want to get Lang.

My Sample Search :

| makeresults 
| eval c="US,UAE",Lang="English,Arabic"
| eval c=split(c,","), Lang=split(Lang,",")
| eval Ans = mvindex(Lang,mvfind(c,"US"))
| table Ans

 

Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The 'ans' field is blank because the 'c' field value is not "US".  If none of the expressions in a case function evaluate to true then the result is NULL.  That is why it's good practice to ensure the last expression always is true by using "1==1" or "true()".

---
If this reply helps you, Karma would be appreciated.

Khuzair81
Path Finder

@richgalloway

c= US

Language = abcdENGLISH123qw

..... | rex fields=Language "\w{4}(?<myval>)\d{4}"

|  eval ans=case(c="US",myval, true(),  "NA" )  | table ans, myval, c

Result

ans = NA

myval = English

c = US

 

I want the ans = English

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...