Splunk Search

Field extraction from pre-defined text

mbasharat
Builder

I have a text file in below format. We are monitoring this file in Splunk. This file has like entries in new lines with different values but in exact same format. This data is a fixed format already defined.

fR0226672024ABCOL41333311023S02315201801 UID03

I need to extract data based on the position labeled in fields properly as below. Using sample data above. Th actual sample is different and I will adjust as needed. I need to have the foundation work.

f: Center Code
R: Mode
0226672024: ID
ABC: Application
OL: Source Code
41333311023: Version
S0: Department
23: Day
10: Month
2018: Year
01: Sequence
(>>): Two spaces for position
UID03: UID

How to have it extracted in above manner. Thanks in-advance!!!!

Tags (1)
0 Karma
1 Solution

nabeel652
Builder

Assuming all your fields are of fixed length across all events, this regex whould work in the field extractions

^(?<CentreCode>\w)(?<Mode>\w)(?<ID>\d{10})(?<Application>\w{3})(?<SourceCode>\w{2})(?<Version>\w{11})(?<Department>.{2})(?<Day>\d{2})(?<Month>\d{2})(?<Year>\d{4})(?<Sequence>.{2})\s+(?<UID>.*)$

View solution in original post

nabeel652
Builder

Assuming all your fields are of fixed length across all events, this regex whould work in the field extractions

^(?<CentreCode>\w)(?<Mode>\w)(?<ID>\d{10})(?<Application>\w{3})(?<SourceCode>\w{2})(?<Version>\w{11})(?<Department>.{2})(?<Day>\d{2})(?<Month>\d{2})(?<Year>\d{4})(?<Sequence>.{2})\s+(?<UID>.*)$

mbasharat
Builder

salam @ nabeel652,

with slight adjustment in use case, this worked with fixed position. THANKS!!! I have another challenging situation come up yesterday for RegEx. Will be posting a separate question tonight.

0 Karma

nabeel652
Builder

Wa'salam brother. Glad it helped!

0 Karma

nabeel652
Builder

are the fields like ID and SourceCode or Version of same length in each event?

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...