Splunk Search

How to compare output of a search to a lookup file?

mkamal18
New Member

Hello,

I have a lookup filled with hostnames. I want to compare the hostnames with the host field in the index.

If the hostname has data in the index then the status will be OK if not KO.

Could you please help me ?

Tags (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi mkamal18,
if in your lookup there's another field with values for each host (e.g. "description") try something like this

| metasearch index=my_index
| dedup host
| lookup mylookup.csv host OUTPUT description
| eval Status=if(description=*,""OK","KO")
| table host Status

if in your lookup there isn't any additional field, try something like this:

| metasearch index=my_index [ | inputlookup mylookup.csv | dedup host | fields host ]
| dedup host
| eval Status="OK"
| append [ 
   | metasearch index=my_index NOT [ | inputlookup mylookup.csv | dedup host | fields host ]
   | dedup host
   | eval Status="KO"
   ]
| table host Status

In both cases, beware to the case of the host.
Bye.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi mkamal18,
if in your lookup there's another field with values for each host (e.g. "description") try something like this

| metasearch index=my_index
| dedup host
| lookup mylookup.csv host OUTPUT description
| eval Status=if(description=*,""OK","KO")
| table host Status

if in your lookup there isn't any additional field, try something like this:

| metasearch index=my_index [ | inputlookup mylookup.csv | dedup host | fields host ]
| dedup host
| eval Status="OK"
| append [ 
   | metasearch index=my_index NOT [ | inputlookup mylookup.csv | dedup host | fields host ]
   | dedup host
   | eval Status="KO"
   ]
| table host Status

In both cases, beware to the case of the host.
Bye.
Giuseppe

0 Karma

cboillot
Contributor

I know this was awhile ago, but how would one go about doing this to state if the host is just in the search results, only in the lookup, or in both?

0 Karma

mkamal18
New Member

Hello,

Thank you Giuseppe, It was really helpful. 🙂

0 Karma
Get Updates on the Splunk Community!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...

Data Management Digest – November 2025

  Welcome to the inaugural edition of Data Management Digest! As your trusted partner in data innovation, the ...