Splunk Search

splitting key/value pair from a field without space

anasar
New Member

Hi,

One of my field is dc_size, which has value "US_0UK_9SG_20CA_5". Please let me know how to split it to key value pair as,
US 0
UK 9
SG 20
CA 5

and graph trends for US, UK, SG and CA.

Thank you.

Tags (1)
0 Karma
1 Solution

javiergn
Super Champion

Either this if you want it to be multivalued (ignore the first two lines that I used to replicate your use case):

| stats count | fields - count
| eval raw = "US_0UK_9SG_20CA_5"
| rex field=raw max_match=0 "(?<DC>[A-Za-z]+)_(?<Size>\d+)"
| table DC, Size

Or this if you want it to be separate events:

| stats count | fields - count
| eval raw = "US_0UK_9SG_20CA_5"
| rex field=raw max_match=0 "(?<DCSize>[A-Za-z]+_\d+)"
| mvexpand DCSize
| rex field=DCSize "(?<DC>[A-Za-z]+)_(?<Size>\d+)"
| table DC, Size

View solution in original post

javiergn
Super Champion

Either this if you want it to be multivalued (ignore the first two lines that I used to replicate your use case):

| stats count | fields - count
| eval raw = "US_0UK_9SG_20CA_5"
| rex field=raw max_match=0 "(?<DC>[A-Za-z]+)_(?<Size>\d+)"
| table DC, Size

Or this if you want it to be separate events:

| stats count | fields - count
| eval raw = "US_0UK_9SG_20CA_5"
| rex field=raw max_match=0 "(?<DCSize>[A-Za-z]+_\d+)"
| mvexpand DCSize
| rex field=DCSize "(?<DC>[A-Za-z]+)_(?<Size>\d+)"
| table DC, Size

anasar
New Member

sorry for the delay javiergn. your answers worked perfectly for me.

0 Karma
Get Updates on the Splunk Community!

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...