Splunk Search

How to extract a field based on character count?

eamuncal
Explorer

I have a field name X with the following value: 0123456789.
I want to create another field that is based on the first 4 characters of the field name X.
Then call it Y.

Any idea on how to do this? If its in bash my way would be to use cut -c1-4

Trying the regex and rex to no avail.

Thanks in advance.

emn.

Tags (2)
0 Karma
1 Solution

Ayn
Legend

This should do it:

rex field=X "^(?<Y>\d{4})"

View solution in original post

Ayn
Legend

This should do it:

rex field=X "^(?<Y>\d{4})"

eamuncal
Explorer

This sure did it! Thanks Ayn

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...