Splunk Search

Find data in indexes with only two leters in the title

hartfoml
Motivator

I have lots of indexes All of the Organizations have there data in indexes with only two letters like index=os

I want to do a search like this [ *| stats distinct_count(host) by index ] to find all the hosts for each org but I only want the indexes with two letters.

I tried this [ * | regex org="index=(?\w\w)\s" | stats distinct_count(host) by org ] but it did not work

Can anyone help

Tags (2)
0 Karma
1 Solution

lukejadamec
Super Champion

Try using rex instead:

index=* |rex field=index "^(?P<org>\w\w)$" | stats distinct_count(host) by org 

It should grab only indexes with 2 letter names, and create a field called org.

View solution in original post

lukejadamec
Super Champion

Try using rex instead:

index=* |rex field=index "^(?P<org>\w\w)$" | stats distinct_count(host) by org 

It should grab only indexes with 2 letter names, and create a field called org.

hartfoml
Motivator

Thanks this worked

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...