Splunk Search

How to extract content between two strings?

senthamilselvan
Engager

Hi Team,

I have an error message coming up in Splunk like below. The required log message will come in the middle of the line and i have to extract the content which lies between SQL0911N & SQLSTATE=40001 .

********* SQL0911N  ##############.  SQLSTATE=40001

Can you please help us to write rex to extract the fields in between the 2 strings. Please let me know if need more information.

Thanks & Regards
Senthamilselvan J

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | rex "SQL\d+N\s*(?<YouFieldNameHere>.+)\s*SQLSTATE=\d+"

View solution in original post

woodcock
Esteemed Legend

Like this:

... | rex "SQL\d+N\s*(?<YouFieldNameHere>.+)\s*SQLSTATE=\d+"

senthamilselvan
Engager

Thank you!! As of now we are getting output excluding the key values (SQL\d+N\s & SQLSTATE=\d+). But i want to display both the key values in the error message as well. Please let me know the rex to includes the key values also.

0 Karma

woodcock
Esteemed Legend

... | rex "(?SQL\d+N)\s*(?.+)\s*SQLSTATE=(?\d+)"

0 Karma

senthamilselvan
Engager

Hi Woodcock,

The search query is not working as expected, Still i am getting message excluding the two key values(SQL\d+N\s & SQLSTATE=\d).

0 Karma

somesoni2
SplunkTrust
SplunkTrust

If those strings (SQL0911N & SQLSTATE=40001) are static/fixed, try like this for inline extraction in search

your base search | rex "SQL0911N\s*(?<YourFieldName>.+)\s*SQLSTATE=40001"
0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...