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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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