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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Manage Edge Processor pipelines end to end with APIs

This guide uses the Data Management APIs to create an Edge Processor, onboard one instance, deploy a pipeline ...

Splunk Brings Proof of Control to Digital Asset Transfers

Digital assets now sit inside the core of financial services. HSBC launched its Tokenized Deposit Service in ...

Manage Ingest Processor pipelines end to end with APIs

This guide uses the Data Management APIs to create an Ingest Processor pipeline, deploy it to the ...