Splunk Search

Creating a new field depending on wildcard search

ajdyer2000
Path Finder

Hi I know this is probably an easy one but I'm new and need some help.

I have the following Field Called "Account Name"

Account Name                                  

Alan Test Account                             

Debbie Production Account         

John Dev Account                            

Ed Test Account                                 

I would like to create a new field called Environment that matches Test, Production ,Dev

Account Name                                  Environment

Alan Test Account                             Test

Debbie Production Account         Production

John Dev Account                            Dev

Ed Test Account                                 Test

Labels (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

One possible approach:

<your search>
| rex field='Account Name' "\S+\s(?<Environment>\S+)\sAccount"
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

You can validate that you are extracting the environment field from all the results with the below query:

<your search>
| rex field='Account Name' "\S+\s(?<Environment>\S+)\sAccount"
| search NOT Environment=*
| table "Account Name"

If you see any results that mean those account names are differently formatted than what you provided examples here.

If you have "No results" in this search you are good to go. You can use the solution provided by @PickleRick .

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!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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