Splunk Search

Matching showing incorrect values

RobertEttinger8
Loves-to-Learn Lots

Hi guys & girls,

about the following query:

| makeresults
| eval expectedm="10"
| eval expectedM="1"
| eval match=case(match(expectedm, expectedM), "Yes", true(), "No")
| eval match1=if(expectedm=expectedM, "Yes", "No")

...Why are the results different? It's almost like the MATCH command is adding a hidden .* at the end of the string ... If so, how to fix this?

Thank you,
Robert

Tags (3)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The match function expects a regular expression as its second argument. Every regex has an implicit .* at each end unless an anchor is used. That means the match in your sample code will match any expectedm that contains the digit '1'. To look for exactly "1", use expectedM=^1$.

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

RobertEttinger8
Loves-to-Learn Lots

Thank you for the explanation, but ... I am comparing two fields, so I cannot add the regex ^ and $ parameters to the match command, or can I?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You can use a temporary field for the comparison.

| makeresults
| eval expectedm="10"
| eval expectedM="1"
| eval matchField="^".expectedM."$"
| eval match=case(match(expectedm, matchField), "Yes", true(), "No")
| eval match1=if(expectedm=expectedM, "Yes", "No")
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk Cloud | Empowering Splunk Administrators with Admin Config Service (ACS)

Greetings, Splunk Cloud Admins and Splunk enthusiasts! The Admin Configuration Service (ACS) team is excited ...

Tech Talk | One Log to Rule Them All

One log to rule them all: how you can centralize your troubleshooting with Splunk logs We know how important ...

Splunk Security Content for Threat Detection & Response, Q1 Roundup

Join Principal Threat Researcher, Michael Haag, as he walks through: An introduction to the Splunk Threat ...