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!

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...

IM Landing Page Filter - Now Available

We’ve added the capability for you to filter across the summary details on the main Infrastructure Monitoring ...

Dynamic Links from Alerts to IM Navigators - New in Observability Cloud

Splunk continues to improve the troubleshooting experience in Observability Cloud with this latest enhancement ...