Splunk Search

How to rex field in unstructured flat file events

jhantuSplunk
New Member

I am breaking every line in flat file and trying to fetch the field using rex, this is how my events looks like:

98000020200512 -992.00 0.00 001 01
98000020200523 830566.00 0.00 001 02
98000020200515 -7356.00 0.00 001 03
98000020200516 -18760.00 0.00 001 04
98000020200518 764074.00 0.00 001 05
98000020200530 165432.00 0.00 001 06
98000020200531 98715.00 0.00 001 07
98000020200511 119993.00 0.00 001 08
98000020200502 908831.00 0.00 001 09
12000020200507 -5481.00 0.00 001 10

The bold digits need to be extracted as Amount field, where the values could be a negative or positive amount.

0 Karma

to4kawa
Ultra Champion

props.conf

TIME_PREFIX = \d{6}
TIME_FORMAT = %Y%m%d
SHOULD_LINEMERGE = false
EXTRACT-unst = ^\d+\s+(?<Amount>[^ ]+)\s+(?<fieldA>[^ ]+)\s+(?<fieldB>[^ ]+)\s+(?<fieldC>[^ ]+)
0 Karma

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval temp="98000020200512 -992.00 0.00 001 01,
98000020200523 830566.00 0.00 001 02,
98000020200515 -7356.00 0.00 001 03,
98000020200516 -18760.00 0.00 001 04,
98000020200518 764074.00 0.00 001 05,
98000020200530 165432.00 0.00 001 06,
98000020200531 98715.00 0.00 001 07,
98000020200511 119993.00 0.00 001 08,
98000020200502 908831.00 0.00 001 09,
12000020200507 -5481.00 0.00 001 10" 
| makemv delim="," temp 
| mvexpand temp 
| eval result= mvindex(split(temp," "),1) 
| table result
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @jhantuSplunk,
try this regex

^\d+\s+(?<Amount>[^ ]+)

that you can test at https://regex101.com/r/F24fG0/1

Ciao.
Giuseppe

0 Karma
Get Updates on the Splunk Community!

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 at Splunk .conf24 ...

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

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...