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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Think Like an Architect: Introducing the Splunk Certified Cybersecurity Defense ...

In cybersecurity, defenders respond to threats. Architects design the systems that stop them.    As ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...