Splunk Search

lose one event if another one exists using dedup

darrend
Path Finder

Hi Guys

I am trying to automatically create a lookup table based on results from searches, part of the search will be to feed results back in from the previously generated lookup, something like this:

search for some stuff | append [previousoutput.csv] |eval field3=if(is null(field3),"unknown",field3)

This gets me so far and gives me results like:

field1,field2,field3
hannah,green,banana
clive,red,unknown
hannah,green,unknown

This is where i am coming unstuck, i want the output lookup i generate off of the back of this to be reduplicated, 1 entry per user, but i only want to keep the amended version of field 3 if it exists, if an amended version of field 3 does not exist then i would like to populate the output with unknown, so my output csv would look like:

field1,field2,field3
hannah,green,banana
clive,red,unknown

Any ideas?

Thanks
Darren

0 Karma

landen99
Motivator
yourstuff | eval field3=if(isnull(field3),"zzzzzzzz",field3) | sort limit=0 field3 | dedup keepempty=t field3 | eval field3=if((field3)="zzzzzzzz","unknown",field3)
0 Karma

somesoni2
Revered Legend

Try following (assuming we get only two duplicate entries, one with amended value and one with "Unknown")

search for some stuff | append [previousoutput.csv] |eval field3=if(is null(field3),"unknown",field3)
 | dedup field1, field2, field3| mvcombine field3 delim="," |eval val1=mvindex(field3,0) | eval val2=mvindex(field3,1) | eval field3=case(val1="Unknown" AND isnotnull(val2), val2, 1=1,val1)

This combines field3 for duplicate values for field1 and field2 (field3 is different,field3=amendedValue and field3=Unknown) into one mv field and then takes the first non "unknown" value for it.

0 Karma

Ayn
Legend

Well, dedup? 🙂

... | dedup field1 field2
0 Karma

darrend
Path Finder

That's what i originally tried, but with that approach there is no guarantee that you won't end up with:

field1,field2,field3
hannah,green,unknown
clive,red,unknown

I may not of worded my original question very well, but i need to guarantee that the alternate value gets kept if the alternate and the "unknown" values both exist. I cannot do a sort as the alternate value will become a user controlled free text field in my app.

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...