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!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...