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!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...