Splunk Search

Using rex to find matching values.

veera9
New Member

I have the following
ACTION :[7] 'CONNECT'
DATABASE[1] 'SYSTEM'

That's in the _raw data.
How do I extract CONNECT and SYSTEM under headers ACTION and DATABASE?

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi veera9,
Try this

ACTION\s:\[\d\]\s\'(?<ACTION>[^\']*)\'\s+DATABASE\[\d+\]\s\'(?<DATABASE>[^\']*)\'

You can test it at https://regex101.com/r/2BwU4O/1

Bye.
Giuseppe

DalJeanis
Legend

That would be

 | rex "ACTION\s:\[\d\]\s\'(?<ACTION>[^\']*)\'\s+DATABASE\[\d+\]\s\'(?<DATABASE>[^\']*)\'"

The above works fine. Based on your example breaking across lines, I might go with

 | rex "ACTION\s:\[\d\]\s\'(?<ACTION>[^\']*)\'"
 | rex "DATABASE\[\d+\]\s\'(?<DATABASE>[^\']*)\'"

...or...

 | rex "ACTION\s:\[\d\]\s\'(?<ACTION>[^\']*)\'|DATABASE\[\d+\]\s\'(?<DATABASE>[^\']*)\'" max_match=0

Any of the above should work.

0 Karma

veera9
New Member

Thank you everyone.

0 Karma

gcusello
SplunkTrust
SplunkTrust

If you're satisfied, please accept or upvote this answer.
Bye.
Giuseppe

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...