Splunk Search

Adding delimiter to a field values

Laxman24
Explorer

Hi all,

I need some help in creating a new field,

I have a field like following

Field 1
AABBCCDDEEFF
AAAABBBBCCCC

 

Id like to make a new field and the values become :

AA-BB-CC-DD-EE-FF
AA-AA-BB-BB-CC-CC

 

could someone help me with this?

Thanks in advance!

Labels (1)
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex mode=sed "s/(?<pair>\w{2})/\1-/g s/-$//g"

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| rex mode=sed "s/(?<pair>\w{2})/\1-/g s/-$//g"

ayushisrivastav
Engager

Hi @ITWhisperer , 

please can you explain me the regular expression which you have written to fulfil the request.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Firstly, rex is put into stream-edit (sed) mode.

The regular expression is in two parts (separated by a space)

Secondly, the first sed expression means substitute (s) the captured group (?<pair>\w{2}) of 2 word-characters with the first captured group (\1) followed by a hyphen (1) done globally (g) through the field.

Thirdly, the second sed expression means substitute (s) the hyphen (-) at the end ($) for nothing i.e. remove it.

Laxman24
Explorer

Thank you!!!! 🙂 it works

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...