Splunk Search

How to remove Search Results from lookup file?

Splunkadmin1876
Engager

Hi All,

I have a search with a subsearch that references a lookup file test.csv with a single field. "Account_Name". I want to remove names from the lookup table that meet a certain criteria. 

The search below currently gives the results that I want removed from the lookup file test.csv, but I cannot seem to figure out how to get the inverse of these results from the lookup file. I want everything in the lookup that does not match the result of the below query. Any advice? For example, if the below search outputs Bob and the lookup contains Bob, Alice, and Dave, I would want my final results to be Alice and Dave to overwrite back into test.csv. That's my line of thinking at least, I could be approaching this in a bad way.

 

index=exampleindex EventCode=4722 | stats by Target_Account_Name | rename Target_Account_Name as Account_Name | search [inputlookup test.csv | table Account_Name] | table Account_Name

 

 

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

So, you want to exclude account names which are present in data, so do it like this

index=exampleindex EventCode=4722 
| stats by Target_Account_Name 
| rename Target_Account_Name as Account_Name 
| eval origin=1
| append
    [ inputlookup test.csv 
    | table Account_Name
    | eval origin=0] 
| stats max(origin) as origin by Account_Name
| where origin=0

i.e. for all events, set the origin=1. Then append the entire lookup with origin=0 and do a max of origin by name. Those where the max origin is 0 are ONLY from lookup, so the where clause will pick them

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

So, you want to exclude account names which are present in data, so do it like this

index=exampleindex EventCode=4722 
| stats by Target_Account_Name 
| rename Target_Account_Name as Account_Name 
| eval origin=1
| append
    [ inputlookup test.csv 
    | table Account_Name
    | eval origin=0] 
| stats max(origin) as origin by Account_Name
| where origin=0

i.e. for all events, set the origin=1. Then append the entire lookup with origin=0 and do a max of origin by name. Those where the max origin is 0 are ONLY from lookup, so the where clause will pick them

 

Splunkadmin1876
Engager

Thanks for the suggestion!

I was also able to do what I wanted with the below search, but yours seems a bit more efficient.

| inputlookup test.csv | search NOT [search index=exampleindex EventCode=4722 | stats by Target_Account_Name | rename Target_Account_Name as Account_Name | table Account_Name ]
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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...