Splunk Search

How do you extract the following field using the rex command?

shubhambhagat02
New Member

Additional backup items: /db/cos7j.dump.Z /db/PSCSS.dump.Z /db/imqdb0152.dump.Z

I want to extract 0152 from this.

Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

@shubhambhagat02,

Try

|rex  "imqdb(?<MY_NUMBER>\d+[^.])"
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

shubhambhagat02
New Member

I tried |rex field=_raw "imqdb(?\d+[^.])"|table MY_NUMBER but no result came

0 Karma

renjith_nair
Legend

@shubhambhagat02, do you have <MY_NUMBER> inside the group ?

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

shubhambhagat02
New Member

@renjith.nair @sudosplunk
my original data is like
10/10/2010 - 15:59:39 --- process started ...
Additional backup items: /db/cos7j.dump.Z /db/PSCSS.dump.Z /db/imqdb0152.dump.Z
I tried
rex field=_raw "imqdb(?\d+)" also still number is not comming

0 Karma

sudosplunk
Motivator

The regex will not work if you do not specify a name for your name capturing group (?<>). Have a look at both the links below and you will see the difference.

Working regex: https://regex101.com/r/kLoHpn/1

Non-working regex: https://regex101.com/r/8bg9sI/1

0 Karma

shubhambhagat02
New Member

I tried this with using group also still no result

0 Karma

shubhambhagat02
New Member

It worked...
Thanks

0 Karma

Vijeta
Influencer

Try this

 |rex field=_raw “/\w+(?<test>\d{4}).”| table test
0 Karma

Vijeta
Influencer

You can use

|rex field=_raw “/\w+(?<test>\d{4}).”
0 Karma

renjith_nair
Legend

@shubhambhagat02,

Try

|rex  "imqdb(?<MY_NUMBER>\d+[^.])"
---
What goes around comes around. If it helps, hit it with Karma 🙂

sudosplunk
Motivator

@shubhambhagat02,

Renjith.nair's solution should work according to the sample you provided. I slightly modified the regex so that it will take less steps to find the match.

Add this to your search: your search | rex field=_raw "imqdb(?<MY_NUMBER>\d+)" | table MY_NUMBER

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...