Splunk Search

How to pass a variable as the output column name in the lookup command?

ddelmont
Explorer

Hello,

Having trouble understanding lookups.  Any help would be appreciated.

If I have a table with ID and User columns and run below it works.

|makeresults
|eval ID="1"
|lookup test.csv ID output User

But if I add a second eval and run:

|makeresults
|eval ID="1"
|eval column="User"
|lookup test.csv ID output column

I get and error "Count not find all of the specified destination fields in the lookup table".

I need to be able to evaluate the column before passing it to the lookup command.  Is that possible? 

Thanks!

Labels (1)
Tags (1)
0 Karma

thambisetty
SplunkTrust
SplunkTrust

@ddelmont 

yes, you can define field which you would like look up against field from lookup table. Fields mentioned after output/outputnew are output of matched field.

why do you want to define variable in output?

————————————
If this helps, give a like below.
0 Karma

ddelmont
Explorer

So it's only possible to use a variable before the output and not after?  Anyway around this?  Thanks.

0 Karma

thambisetty
SplunkTrust
SplunkTrust

@ddelmont 

The lookup syntax is not correct. 

field/column names which are used after output keyword are expected to be in lookup and those field values will be returned if there is any match against the field you specify before output keyword.

The correct syntax is as below:

| lookup <lookup-table-name> <lookup-field1> AS <event-field1>, <lookup-field2> AS <event-field2> OUTPUTNEW <lookup-destfield1> AS <event-destfield1>, <lookup-destfield2> AS <event-destfield2>

https://docs.splunk.com/Documentation/Splunk/8.1.0/SearchReference/Lookup

https://www.youtube.com/watch?v=cwEzgY0lAts 

————————————
If this helps, give a like below.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...