Splunk Search

How to remove a prefix on a field during search?

aba83
Explorer

Hello, I'm trying to normalize a field during search. I have the field "user" and some of the fields are "NAU\abc123". I'm trying to remove the prefix "NAU\". All I want is the abc123 part of it. Is there a way to remove that prefix in search? Thanks in advance.

0 Karma
1 Solution

kmorris_splunk
Splunk Employee
Splunk Employee

You can use rex in your search. Try this out.

[YOUR BASE SEARCH]
| rex field=user "\w{3}\\\(?<user2>\S+)"

View solution in original post

adonio
Ultra Champion

hello aba,
a little confusing as you suggest both "user" and "NAU\abc123" are fields, are NAU\abc123 fields or values under the field user?

0 Karma

aba83
Explorer

Sorry, user is the column name. It's just sometimes those fields in the column populate either with just the abc123 or they populate with NAU\abc123. They aren't consistent. Sorry for the confusion. I'm trying to make it so every field in the user column is just the userid without the prefix "NAU\".

0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

You can use rex in your search. Try this out.

[YOUR BASE SEARCH]
| rex field=user "\w{3}\\\(?<user2>\S+)"

aba83
Explorer

This worked, thank you!

0 Karma

cmerriman
Super Champion

i think you have one extra backslash in here. \w{3}\\(?<user2>\S+)

0 Karma

kmorris_splunk
Splunk Employee
Splunk Employee

It was escaping the parenthesis with only 2. I had to add the extra. This is something to do with the Rex command.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...