Splunk Search

How to search for a field value with a wildcard and a variable?

asamajdwar
New Member
index="test_index"
|table Calendar, Job, Status
|eval dayNow=strftime(now(),"%A")
|search Calendar= ???

My 'Calendar' field value is like 'Monday,Wednesday,Saturday'. So if current day(dayNow variable) is say Wednesday, I should get list of jobs for the day. I am trying to use wildcard with the dayNow variable. Something like Calendar = "%dayNow%".
I am not able to find anything to achieve this so far.

0 Karma

DalJeanis
Legend

Try this...

 index="test_index"
 | table Calendar, Job, Status
 | eval dayNow=strftime(now(),"%A")
 | makemv delim="," Calendar
 | mvexpand Calendar
 | where Calendar=dayNow

What the above does is, use the commas to break the Calendar field up into a multivalue field, then use mvexpand to make each record into one record per day that it is supposed to run. After that, we filter to eliminate any records that do not match today's day.

Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...