Splunk Search

How do I extract a string of numbers using rex?

drewabrams
New Member

I am dealing with a SQL log file.
The field I am attempting to extract a string of numbers from is called 'SQL_BIND'. I want to set the extracted string of numbers as field 'numbr'
The data in the SQL_BIND field is in the following form:

#1(8):xxxxxxxx #2(21):...

The xxxxxxxx represents the number I need to extract, the #1(8): exists at the beginning of each, and the #2(21): exists after the number followed by a random set of information (represented by the ellipsis).

I've attempted the following search to get a table of the results, but the table generates completely blankly.

index="main" | rex field=SQL_BIND "\(#1\(8\):()\(\s#2\(21\)" | table numbr

I think I'm using the \ before the parenthesis correctly to treat them as literal characters, but maybe not? I've been at this for hours, scouring the web for an answer or similar issue to figure it out... and so far no luck.

What am I doing wrong? This is driving me bonkers! Can someone please help?

0 Karma
1 Solution

javiergn
SplunkTrust
SplunkTrust

Try this instead:

| rex field=SQL_BIND "#1\(8\):(?<numbr>\d+) #2\(21\)"

View solution in original post

0 Karma

sundareshr
Legend

You need to need to escape the parens with a backslash

... | rex field=SQL_BIND "\#1\(8\):(?<numbr>\d+)" | ...
0 Karma

javiergn
SplunkTrust
SplunkTrust

Try this instead:

| rex field=SQL_BIND "#1\(8\):(?<numbr>\d+) #2\(21\)"
0 Karma

drewabrams
New Member

Thank you! This worked perfectly! Apparently I was overthinking it 🙂

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...