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+[^.])"
Happy Splunking!

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 ?

Happy Splunking!
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+[^.])"
Happy Splunking!

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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...