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!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...