Splunk Search

How to use rex max_match resulting in only unique values

spencerneal
Explorer

Hello,

 

I am trying to get a list of values using max_match=5.  However I need the results to only return unique values and not just list 5 values regardless of them being duplicates.

| rex max_match=5 (?P<BrandID>(202\d.+?))\"

|table BrandID

Your help and energy is greatly appreciated.  🙂

Thank you,

Spencer Neal

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

That's not what rex does.  It just matches patterns.  If you need unique results, then insert the mvdedup function into your query.

```Get all BrandID values```
| rex max_match=0 (?P<BrandID>(202\d.+?))\"
```Filter out duplicate values ```
| eval BrandID=mvdedup(BrandID)
```Keep only the first 5 unique values```
| eval BrandID=mvindex(BrandID, 0 4)
| table BrandID

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

spencerneal
Explorer

Rich,

Thank you greatly for taking the time to help me out!!  :). Your code did the trick!!  

Thank you,

Please take care.

Spencer

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, then please click the "Accept as Solution" button to help future readers.

---
If this reply helps you, Karma would be appreciated.

richgalloway
SplunkTrust
SplunkTrust

That's not what rex does.  It just matches patterns.  If you need unique results, then insert the mvdedup function into your query.

```Get all BrandID values```
| rex max_match=0 (?P<BrandID>(202\d.+?))\"
```Filter out duplicate values ```
| eval BrandID=mvdedup(BrandID)
```Keep only the first 5 unique values```
| eval BrandID=mvindex(BrandID, 0 4)
| table BrandID

 

---
If this reply helps you, Karma would be appreciated.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...