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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...