Splunk Search

How to extract username from my data?

thambisetty_bal
Path Finder

Hi Splunkers,

I have been struggling to extract user name from below values of user.

user
--------
user1@sa.com
sab\user2
user3

OUTPUT
------------
user1
user2
user3

kindly help me out..

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try. (Runanywhere sample search, first line is just to generate sample data).

| gentimes start=-1 | eval user="user1@sa.com sab\user2 user3" | table user | makemv user | mvexpand user 
| rex field=user "(?<cleanedUser>\w+)(\@|$)"

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try. (Runanywhere sample search, first line is just to generate sample data).

| gentimes start=-1 | eval user="user1@sa.com sab\user2 user3" | table user | makemv user | mvexpand user 
| rex field=user "(?<cleanedUser>\w+)(\@|$)"
0 Karma

thambisetty_bal
Path Finder

you are amazing @somesoni2

please explain regex Sir.

0 Karma

somesoni2
Revered Legend

It's capturing a full work (\w+) till you encounter a @ symbol or end of value ($). backward slash is word terminator so it works for 2nd example value as well.

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, ...