Splunk Search

Field Extraction of particular data from user defined field

jlattus
New Member

I'm trying to pull a certain type of data from a field but that field can change into different types of data depending on the log. I only want to keep the particular data and ignore the rest.

An example would be a field called "username". I don't care when username=root but when username="any other user" I want to grab that data only. Is there a way to do this? I appreciate any feedback.

Tags (2)
0 Karma
1 Solution

bbingham
Builder

during search time you can use the command "rex" to extract a piece of another field. rex uses regex on top of any data to create new fields (or replace).

|rex field=username "(?<username2>\w+)"

This builds a new field username2 with any username. So same type of concept, since you can use regex, do conditional lookahead matching:

|rex field=username "(?<username2>(?!root)\w+)"

This should match the field only if root is not matched.

Hope that helps.

View solution in original post

bbingham
Builder

during search time you can use the command "rex" to extract a piece of another field. rex uses regex on top of any data to create new fields (or replace).

|rex field=username "(?<username2>\w+)"

This builds a new field username2 with any username. So same type of concept, since you can use regex, do conditional lookahead matching:

|rex field=username "(?<username2>(?!root)\w+)"

This should match the field only if root is not matched.

Hope that helps.

jlattus
New Member

Awesome thanks!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...