Splunk Search

rex extract number

indeed_2000
Motivator

Hi

2022-01-04 23:10:43,224 INFO [APP] sessionDestroyed, Session Count: 0
2022-01-04 23:12:34,238 INFO [APP] sessionCreated, Session Count: 1

2022-01-04 23:13:43,224 INFO [APP] sessionDestroyed, Session Count: 10
2022-01-04 23:14:34,238 INFO [APP] sessionCreated, Session Count: 7

 

extract output                              sessionCreated            sessionDestroyed

2022-01-04 23:10:43                                                                                0

2022-01-04 23:12:34                           1

2022-01-04 23:13:43                                                                               10

2022-01-04 23:14:34                            7

 

Labels (1)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

You can try this

| rex "sessionCreated, Session Count: (?<sessionCreated>\d+)" 
| rex "sessionDestroyed, Session Count: (?<sessionDestroyed>\d+)"
| table _time sessionCreated sessionDestroyed

r. Ismo 

0 Karma

indeed_2000
Motivator

How about single rex?

0 Karma

isoutamo
SplunkTrust
SplunkTrust
Also that is working, but as you want those to separate variables it's clearer to use two (IMHO)
0 Karma

indeed_2000
Motivator

Actually need to show them on timechart but want extract fields with single rex.

any idea?

 Thanks 

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Maybe this?

| makeresults
| eval _raw="2022-01-04 23:10:43,224 INFO [APP] sessionDestroyed, Session Count: 0
2022-01-04 23:12:34,238 INFO [APP] sessionCreated, Session Count: 1
2022-01-04 23:13:43,224 INFO [APP] sessionDestroyed, Session Count: 10
2022-01-04 23:14:34,238 INFO [APP] sessionCreated, Session Count: 7"
| multikv noheader=t
|  rex "^(?<dt>\d{4}-\d+-\d+ \d+:\d+:\d+,\d+) "
| eval _time = strptime(dt, "%F%T,%3Q")
```Above generates sample data```
| rex "(sessionCreated, Session Count: (?<sessionCreated>\d+))|(sessionDestroyed, Session Count: (?<sessionDestroyed>\d+))"
| table _time sessionCreated sessionDestroyed

indeed_2000
Motivator

Thanks, is it possible to extract these fields more efficiently?

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

What is your definition of "efficiently"?

@isoutamo has given you an answer without you having to work it out yourself; it is a single rex, as you asked for; what can be more efficient than that? 😀😀😀

0 Karma

indeed_2000
Motivator

I try this spl on large dataset and take long time to extract it, so I'm looking for more efficient way to do this.

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Can you extract the event type and count at indexing time?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...