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!

Introducing the Splunk Community Dashboard Challenge!

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

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...