Splunk Search

Lookup for a match with and w/o a preceding 0

neerajs_81
Builder

Hi,  We maintain a lookup table which contains a list of account_id and some other info as shown below.

account_idaccount_ownertype
12345Davidprod
123456Johnnon-prod
45678Natnon-prod


In our query, We use a lookup command to match enrich the data using this lookup table. we match by account_id and get the corresponding owner and type as follows.

 

| lookup accounts.csv account_id OUTPUT account_owner type

 

 
In some events (depending on the source) , the account_id values contains a preceding 0 . But in our lookup table, the account_id column does not have a preceding 0. 


  Basically some events will have account_id = 12345  and some might have account_id=012345.
They both are same accounts though.  Now, The lookup command displays the results when there is an exact exact matching account_id in events,   but fails when there is that extra 0 at the beginning.

How to tune the lookup command to make it search the lookup table for both the conditions - with and without preceding 0 for the account_id field and even if one matches, it should produce the corresponding results ?

Hope i am clear. I am unable to come with a regex for this.



Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust
| rex field=account_id "\b(0?)(?<field_to_look_up>\d+)\b"
| lookup accounts.csv account_id AS field_to_look_up [...]

 

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust
| rex field=account_id "\b(0?)(?<field_to_look_up>\d+)\b"
| lookup accounts.csv account_id AS field_to_look_up [...]

 

0 Karma

neerajs_81
Builder

Thank you

0 Karma
Get Updates on the Splunk Community!

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...