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
Get Updates on the Splunk Community!

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

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...