Splunk Search

How do you combine similar Items in a search?

balcv
Contributor

I have a scenario where I have a data set that contains user ids, among other things, but there are two possible versions of the user id that I would like to be able to combine into a single search result.
For example, user id could be d1\123456 and it could be d2\123456. This is the same user just from a different domain.

index="pan" | stats count by user | sort -count

This will result in a separate line for every unique user

d1\123456      45
d2\123456      83

I would like to be able to get a single line for user 123456 irrespective of the domain (d1 or d2).

123456         128

Is this possible?

Tags (2)
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

index="pan"
| rex field=user mode=sed "s/.*\\\//"
| stats count by user
| sort 0 -count

View solution in original post

woodcock
Esteemed Legend

Like this:

index="pan"
| rex field=user mode=sed "s/.*\\\//"
| stats count by user
| sort 0 -count

balcv
Contributor

@woodcock, thank you, that is exactly what I was after. Simple when you know how.

0 Karma

vnravikumar
Champion

Hi

Try like

| makeresults 
| eval msg="d1\\123456,d2\\123456" 
| makemv delim="," msg 
| rex field=msg "\\\(?P<user>[\d]+)" 
| stats count by user 
| sort -count

balcv
Contributor

Thanks for the response @vnravikumar . What I think I omitted was that the data set will contain hundreds of user ids in the format domain\userid and there could be user ids with just d1, some with just d2 or some with both.

I'm looking for search results showing the unique user ids combining those that have both d1 and d2 while still listing those with just the single domain.

Also, the user id can be both numeric and alpha. (eg some as 123456 others as ajones with the d1 and/or d2 domain).

0 Karma

vnravikumar
Champion

Hi

Try this, if not worked give some sample user ids

| makeresults 
| eval msg="d1\\123456,d2\\123456,ajones,123456" 
| makemv delim="," msg 
| rex field=msg "(\w+\\\){0,1}(?P<user>[\w]+)" 
| stats count by user 
| sort -count
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...