Splunk Search

How to use the results from one inputlookup as a variable in a search of a second inputlookup?

andyp54
New Member

Hello

New to Splunk, so I know there is a simple answer to this, but I just can't find it 🙂

I have two inputlookup files.

input-file-A can be searched by username to return a unique id associated with that username.

I want to use this result to search input-file-B to return any fields associated with the unique id.

| inputlookup input-file-B | search unique_id=$unique_id$ [| inputlookup input-file-A | search user_name ="joe_bloggs" | fields unique_id]

...the subseatch runs and works but it's like the unique-id variable doesn't get passed; if I cut and paste a unique-id into the start of the search it also works (so I know the files are there and can be queried etc.

Any advice greatly appreciated!

0 Karma
1 Solution

alacercogitatus
SplunkTrust
SplunkTrust

Ah, it appears you are using subsearch in a manner to which it is not inclined. When using a subsearch, you do not have to worry about tokenization. Whatever is found in the subsearch is returned in SPL, which gets appended by the primary search.

|inputlookup input-file-B | search [ inputlookup input-file-A | search user_name="joe_bloggs" | fields unique_id ]

So here, your subsearch will return:

( unique_id="joes_uniq_id" )

Which will be appended to a search command, so the "expanded" search would look like this:

| inputlookup input-file-B | search ( unique_id="joes_uniq_id" )

View solution in original post

alacercogitatus
SplunkTrust
SplunkTrust

Ah, it appears you are using subsearch in a manner to which it is not inclined. When using a subsearch, you do not have to worry about tokenization. Whatever is found in the subsearch is returned in SPL, which gets appended by the primary search.

|inputlookup input-file-B | search [ inputlookup input-file-A | search user_name="joe_bloggs" | fields unique_id ]

So here, your subsearch will return:

( unique_id="joes_uniq_id" )

Which will be appended to a search command, so the "expanded" search would look like this:

| inputlookup input-file-B | search ( unique_id="joes_uniq_id" )

andyp54
New Member

@alacercogitatus

Thank you so much, worked perfectly 🙂

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...