Splunk Search

Split string into fields

darkins
Engager
fieldA:1:10 fieldB:1:3 fieldC:1:2
fieldA:1:10 fieldC:1:2
fieldA:1:10 fieldC:1:2
fieldC:1:1

 

I want to end up with a field called fieldA, fieldb, and fieldC where the field name is the actual text found in the string as i cant predict which event will contain which combination

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming your data is in the _raw field

| eval parts=split(_raw, " ")
| mvexpand parts
| eval name=mvindex(split(parts,":"),0)
| eval value=mvjoin(mvindex(split(parts,":"),1,2),":")
| eval {name}=value

darkins
Engager

this is awesome, but is there a way to make the results columns (additional fields on my results)

0 Karma

bowesmana
SplunkTrust
SplunkTrust

If you want to add these fields to a table you are creating but don't know what the fields are called, then you can use @ITWhisperer technique, but change it slightly so that it is

...
| eval cust_field_{name}=value
| table fields_you_want cust_field_*
| rename cust_field_* as *

which will effectively give you cust_field_fieldA and so on with that consistent prefix, then you can use the table statement to table out the fields you want and all those custom fields and then use wildcard rename to get rid of the prefix.

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Please share some raw anonymised events so we can see what you are dealing with so we can try and help you further. Please use the code block </> above to preserve the format of the events so that we can suggest the correct field extractions for you.

0 Karma

dural_yyz
Motivator

Do you mean?

fieldAfieldBfieldC
1:101:31:2
1:10 1:2
1:10 1:2
  1:1
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!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...