Splunk Search

Regex sanity check - fixed record length field extraction

himynamesdave
Contributor

Guys, I have a horrible dataset in Splunk and am trying to match fields based on a position in event.

As an example, I need to extract a field which is found in the 201st and 202nd position of the event. I tried the following extraction (with some iteration) which fails.

| rex (.){200}(?P<FIELD>.{2})

What should it look like?

Thanks!

Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Remove the parentheses from around the first dot and it should work. Of course, the whole regex string must be quoted.

 | rex ".{200}(?P<FIELD>.{2})" | ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Remove the parentheses from around the first dot and it should work. Of course, the whole regex string must be quoted.

 | rex ".{200}(?P<FIELD>.{2})" | ...
---
If this reply helps you, Karma would be appreciated.

jacobwilkins
Communicator

Also, anchor it.

| rex "^.{200}(?P<FIELD>.{2})"

himynamesdave
Contributor

Thanks guys!

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...