Getting Data In

How to split single field value into two different values?

alex389
Engager

Hello,

I'm trying to split a single value of a result which is 5231562. I want to be able to split this number into two different values.

i.e

Field0 5231562 becomes -
Field1 = 52
Field2 = 31562

Thank you

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | rex field=Field0 "^(?<Field1>\d{2})(?<Field2>\d+)$"

View solution in original post

alex389
Engager

Thank you all

woodcock
Esteemed Legend

Don't forget to UpVote, too!

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=Field0 "^(?<Field1>\d{2})(?<Field2>\d+)$"

renjith_nair
Legend

Hi @alex389,

If you just want to split , you could use substr. Lets know in case you need any logic for the first two digits

|stats count|fields - count|eval Field0=5231562|eval Field1=substr(Field0,0,2),Field2=substr(Field0,3)
---
What goes around comes around. If it helps, hit it with Karma 🙂

niketn
Legend

@alex389 if you always want field1 to be first two digits you can write the following rex:

<yourCurrentSearch>
| rex field=field0 "^(?<field1>\d{2})(?<field2>.*)"

Following is a run anywhere search based on sample data and details.

| makeresults
| eval field0="5231562"
| rex field=field0 "^(?<field1>\d{2})(?<field2>.*)"
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

New in Observability - Improvements to Custom Metrics SLOs, Log Observer Connect & ...

The latest enhancements to the Splunk observability portfolio deliver improved SLO management accuracy, better ...

Improve Data Pipelines Using Splunk Data Management

  Register Now   This Tech Talk will explore the pipeline management offerings Edge Processor and Ingest ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

Register Join this Tech Talk to learn how unique features like Service Centric Views, Tag Spotlight, and ...