Splunk Search

Regex to extract multiple fields from single event

gvnd
Path Finder

Hi, I want to extract particular fields from single event based on fields position.

Sample Data:

event1: aaa|bbb|ccc|234| | f5h | |tgvsfj| jhsfj| | | | 6384;
event2: aaa|ggg|hhh|56f| | 563 | |dhr| jhsfj| | | | 6385;

Now, I want to extract 3rd field(i.e ccc) and 7th field(i.e some spaces,nodata)

My data may include spaces.

I need regex to extract those fields only.

Thanks in advance.

0 Karma
1 Solution

dineshraj9
Builder

You see each field is a set of characters which is "NOT |" followed by a "|".

| rex "([^\|]*\|){2}(?<thirdField>[^\|]*)\|([^\|]*\|){3}(?<seventhField>[^\|]*)"

Test regular expressions using https://regex101.com/r/Odnybw/1

View solution in original post

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Please check this -
sourcetype=sample | rex field=_raw "^(?:[^\|\n]*\|){2}(?P<string1>\w+)(?:[^ \n]* ){3}\|(?P<string2>\s+)" | table string1 string2 _raw

alt text

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

dineshraj9
Builder

You see each field is a set of characters which is "NOT |" followed by a "|".

| rex "([^\|]*\|){2}(?<thirdField>[^\|]*)\|([^\|]*\|){3}(?<seventhField>[^\|]*)"

Test regular expressions using https://regex101.com/r/Odnybw/1

0 Karma
Get Updates on the Splunk Community!

Buttercup Games: Further Dashboarding Techniques (Part 6)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Splunk Observability Synthetic Monitoring - Resolved Incident on Detector Alerts

We’ve discovered a bug that affected the auto-clear of Synthetic Detectors in the Splunk Synthetic Monitoring ...