Security

extract username for element in path

kritho
Explorer

Hi,
Im new to regexes, and I'm trying to get the username field configuration to my extract-fields

source:
/u01/somedir/somedir/user1/anotherfile
/u01/somedir/somedir/user3/anotherfile2
/u01/somedir/somedir/user4/anotherfile3

I want to get the "user1|2|3" part to a username field.

Any tips?
brgds/K

Tags (1)
0 Karma

kristian_kolb
Ultra Champion

To do that inline in the search, you can use rex in the example below, look at the fourth element of the path (i.e. source);

your search | rex field=source "/([^/]+/){3}(?<username>[^/]+)"

/K

Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...