Splunk Search

How to run a different rex extraction only if another rex extraction did not find anything to extract?

raby1996
Path Finder

Hi all,

So I'm currently using this extraction:

| rex "(?m)Package:\s+SEA.ha(?:\n|.)*?MS:(?<MS>\s+\d+\-\d+\S\S+)" 

However I have found that this is not always present in my data, so I was wondering if there was a way where I could run this (below) rex command only when the first one doesn't find anything?

 "| rex "(?m)(?:\n|.)MS:(?<MS>\s+\S+)"

Thank you.

0 Karma
1 Solution

somesoni2
Revered Legend

Can you provide some sample logs for both patterns?
One dirty workaround would be like this

| rex "(?m)Package:\s+SEA.ha(?:\n|.)*?MS:(?<MS>\s+\d+\-\d+\S\S+)" | rex "(?m)(?:\n|.)MS:(?<MS1>\s+\S+)" | eval MS=coalesce(MS,MS1)

View solution in original post

somesoni2
Revered Legend

Can you provide some sample logs for both patterns?
One dirty workaround would be like this

| rex "(?m)Package:\s+SEA.ha(?:\n|.)*?MS:(?<MS>\s+\d+\-\d+\S\S+)" | rex "(?m)(?:\n|.)MS:(?<MS1>\s+\S+)" | eval MS=coalesce(MS,MS1)

raby1996
Path Finder

That worked great! thank you

0 Karma

raby1996
Path Finder

If you would like to convert it as an answer I'll accept it for you

0 Karma

somesoni2
Revered Legend

Here you go.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...