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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...