Splunk Search

How do I write an eval statement to return "True" if there is only one non-zero value in a row, else "False"?

lynchs61
New Member

I have results with field names A, B, C, D that will look something like this;

A    B    C    D
0    10   0    0
1    0    4    5
0    3    8    0
0    0    0    2

I'm looking for some type of eval that will give me a true or false as to whether the fields have only ONE value that is non-zero. So in this case the first row (0, 10, 0, 0) and the last row (0, 0, 0, 2) are true and the other two are false.

I could test every permutation, but that seems inefficient. Is there a better way?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I think this will do it if you can put the fields into a single string called "foo", but it's untested.

... | rex field=foo max_match=0 "(?P<zeroes>^0| 0)" | eval onlyOne=if(mvcount(zeroes)==3, "true", "false") | ...
---
If this reply helps you, Karma would be appreciated.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...