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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...