Splunk Search

Extract a field from a field in splunk?

pavanae
Builder

I have a field names "code_value" which has the values as follows 

 

code_value
ABC-123 JHLIK
ABC-456 LKJF
ABC-781 klklk
ABC-22 olsd

 

Now how do I extract the code_value field anything that comes before a space? something like below 

new_field_derived_from_code_value
ABC-123 
ABC-456 
ABC-781 
ABC-22 
Labels (1)
Tags (2)
0 Karma

vnravikumar
Champion

@pavanae , you can try this

| makeresults 
| eval code_value ="ABC-123 JHLIK,
ABC-456 LKJF,
ABC-781 klklk,
ABC-22 olsd" 
| makemv delim="," code_value 
| mvexpand code_value 
| eval result=mvindex(split(code_value," "),0)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

For extracting a field from a field use the rex command.  This regex puts everything up to the first space into the new field.

| rex field=code_value "(?<new_field_derived_from_code_value>\S+)"

 

---
If this reply helps you, Karma would be appreciated.
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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

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