Splunk Search

How to match search query results with lookup fields and replace the query result with lookup field value?

joydeep741
Path Finder

I have a query which gives results like

COLUMN_1      COLUMN_2
1                        a
2                        b 
3                        c
4                        d
5                        e
6                        f

I have a lookup mylookup.csv which has following data

COLUMN_1      COLUMN_2
1                        1000
3                        1111
6                        2222

My query should search each value in column 1 and If its present in the lookup (mylookup.csv) replace the value of coulmn 2 with the value from column 2 of lookup.

The final result of my query should look like

 COLUMN_1      COLUMN_2
**1                        1000**
2                        b 
**3                        1111**
4                        d
5                        e
**6                        2222**
0 Karma

Shan
Builder

@joydeep741,

Try below query.
I have just provided an example.
You can consider only this part for your logic | eval tableval2=if(tableval1=lookupval1,lookupval2,tableval2)
I believe you are well aware of how to use lookup and how lookup logic works.

| makeresults 
| eval tableval1=mvappend("1","2","3","4","5","6")
| eval tableval2 =mvappend("a","b","c","d","e","f")
| mvexpand tableval1
| mvexpand tableval2
| table tableval1 tableval2
| appendcols  [| makeresults          
          | eval lookupval1 =mvappend("1","3","6")
          | eval  lookupval2=mvappend("1000","1111","2222")
          | mvexpand lookupval1
          | mvexpand lookupval2
          | table lookupval1 lookupval2
          ]         
          | eval tableval2=if(tableval1=lookupval1,lookupval2,tableval2)
          | table *

Thanks..

0 Karma

renjith_nair
Legend

@joydeep741,

Try

index="my_index" |fields COLUMN_1,COLUMN_2|lookup mylookup.csv  COLUMN_1 OUTPUT COLUMN_2 as tmp
|eval COLUMN_2=coalesce(tmp,COLUMN_2)|fields - tmp
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...

Everything Community at .conf24!

You may have seen mention of the .conf Community Zone 'round these parts and found yourself wondering what ...

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...