Splunk Search

Wildcard * does not work with If or Case in Splunk

gndivya
Explorer

There are 3 different values for one particular field say field1 - "INTPAY\ITS\TD_EFT\can contain other data", "INTPAY\TD_EFT\can contain other data", "Expense_EFT\can contain other data"

Below eval statement doesn't work:

| eval Flag=case((field1 like "INTPAY%TD_EFT%" OR field1 like "INTPAY%ITS%TD_EFT%") ,"1",(field1 like "Expense_EFT%"),"2",1=1,"3")

How can I write a search to get the below requirement:

If field1 is "INTPAY\ITS\TD_EFT\can contain other data" or "INTPAY\TD_EFT\can contain other data", flag should be 1, if field1 is "Expense_EFT\can contain other data", flag should be 2. If none matches, flag should be 3.

Have tried with INTPAY\TD_EFT also.

Please help.

woodcock
Esteemed Legend

You can use like, match, or searchmatch. Try this:

.... | eval Flag=case(
    match(field1, "^INTPAY\\(ITS\\)?TD_EFT\\") ,"1",
    match(field1, "^Expense_EFT\\"),"2",
    true(),"3")
0 Karma

aberkow
Builder

Hi - I think you can leverage the match command (https://docs.splunk.com/Documentation/Splunk/8.0.0/SearchReference/ConditionalFunctions#match.28SUBJ...) to achieve your desired outcome:

| makeresults count=1
| streamstats count
| eval field=case(count=1, "INTPAY\\TD_EFT\\")
| eval field2=case(match(field, "TD_EFT"), "1")

You can improve upon the regex outside of my suggestion if you'd like.

Hope this helps! Please accept the answer/upvote if it does.

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!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...