Splunk Search

How do you compare dynamic field values created after xyseries?

bapunpatel
New Member

I have the below output after my xyseries

comp, Field1,Field2,Field3
A,a1,a1,a1
B,b1,b2,b3
C,c1,c2,c2

I want to add a last column which compares 2nd to 4th column values and give compare results.

Expected Result

comp, Field1,Field2,Field3,Match

A,a1,a1,a1,Yes
B,b1,b2,b3,No
C,c1,c2,c2,No

Note: the no of fields are dynamic there can be n fields Field1...Fieldn

Any help in this regard will be much appreciated.

0 Karma
1 Solution

vnravikumar
Champion

Hi @bapunpatel

Try this, here I had considered Field*(Field1,Field2,....)

source="values.csv" host="dpds" sourcetype="csv" 
| eval match="" 
| foreach Field* 
    [ eval match = match.",".<<FIELD>>] 
| makemv match delim="," 
| mvexpand match 
| eventstats dc(match) as temp by comp 
| eval match = if(temp==1,"Yes","No") 
| mvcombine match 
| eval match = mvdedup(match) 
| table comp,Field*,match

alt text

View solution in original post

0 Karma

vnravikumar
Champion

Hi @bapunpatel

Try this, here I had considered Field*(Field1,Field2,....)

source="values.csv" host="dpds" sourcetype="csv" 
| eval match="" 
| foreach Field* 
    [ eval match = match.",".<<FIELD>>] 
| makemv match delim="," 
| mvexpand match 
| eventstats dc(match) as temp by comp 
| eval match = if(temp==1,"Yes","No") 
| mvcombine match 
| eval match = mvdedup(match) 
| table comp,Field*,match

alt text

0 Karma

bapunpatel
New Member

@vnravikumar - That worked like a charm. Thank you. Just needed one adjustment - replace <> with '<>' when field names contain special characters like Field1_name or Field2-job etc...

0 Karma

tiagofbmm
Influencer

I'm assuming a simple comparison with the field names won't be possible for you? eval comparison=if(Field1=Field3, "Yes","No")

0 Karma

bapunpatel
New Member

@Tiago - Thanks for the quick response. This works if the fields are known. Looking for a way to achieve this when the no of fields and field names are dynamic.

0 Karma
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!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

Ready to make your IT operations smarter and more efficient? Discover how to automate Splunk alerts with Red ...