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
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...