Splunk Search

Rex how to return static text instead of unmatched field?

giovere
Path Finder

I'm trying to apply a regular expression on input, if regex is not matched I'd like to return a static text as a field value (NULL for example). Splunk 4.3.7.

My current query looks like this, but this would return anything only if all rexes are matched, in example below just first line would work.
Any suggestions how can I get it working?

... | rex "Name=(?.+?);" | rex "Age=?(?.+?);" | rex "Weight=?(?.+?);"

Input:

Some random text; Name=Ruby; Age=18; yada yada; Weight=50

Some random text; Name=Bon; Age=19;

Some random text; Age=18; yada yada; Weight=52

Desired output

Name,Age,Weight

Ruby,18,50

Bon,19,NULL

NULL,18,52

Tags (2)
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

your base search | rex "Name=(?<name>\w+)" | rex "Age=?(?<age>\w+)" | rex "Weight=?(?<weight>\w+)" | fillnull value=NULL

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try this

your base search | rex "Name=(?<name>\w+)" | rex "Age=?(?<age>\w+)" | rex "Weight=?(?<weight>\w+)" | fillnull value=NULL
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...