Splunk Search

Get just 7 characters of field to search

dlcrooks
Explorer

I have a userID with 9 characters and want to search a lookup with just 7 characters. I have tried to use RegEx but it just searches that many characters instead of assigning it to the field. Any ideas?

Tags (1)
0 Karma
1 Solution

493669
Super Champion

Try:

 <base search>|eval userID =substr(userID,1,7)

Hope this helps!

View solution in original post

mayurr98
Super Champion

you can do this using rex as well

Try this run anywhere search

| makeresults 
| eval userID="dlcrooks mayurjadhav splunkninja dlcrook123 dl123crooks" 
| makemv userID 
| mvexpand userID 
| rex field=userID "(?<userID>\w{7})"

In your environment, you should write

index=<your_index> 
| rex field=userID "(?<userID>\w{7})"

let me know if this helps!

0 Karma

493669
Super Champion

Try:

 <base search>|eval userID =substr(userID,1,7)

Hope this helps!

dlcrooks
Explorer

Thanks! It works!

0 Karma

493669
Super Champion

@dlcrooks, please accept answer so that it will no longer open

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...