Splunk Search

How to replace blank with "NA" while using Rex command

manojchacko78
Path Finder

I am extracting these three values and if there is any empty value in any of the fields, it returns as no result.

How i replace the blank values with NA in the rex statements

 

| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]+)"
| rex field=AddtionalData "Location code:(?<Locationcode>[^,]+)"
| rex field=AddtionalData "Job code :(?<Jobcode>[^,]+)"

| stats count by  BusinessUnit Locationcode Jobcode
| fields - count

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @manojchacko78,

you can use fillnull to replace spaces with  "NA"

| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]+)"
| rex field=AddtionalData "Location code:(?<Locationcode>[^,]+)"
| rex field=AddtionalData "Job code :(?<Jobcode>[^,]+)"
| fillnull value="NA" BusinessUnit 
| fillnull value="NA" Locationcode 
| fillnull value="NA" Jobcode
| stats count by  BusinessUnit Locationcode Jobcode
| fields - count

Ciao.

Giuseppe

View solution in original post

manojchacko78
Path Finder

Thanks @gcusello 

Perfect, thanks, it worked

Have a nice day

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @manojchacko78,

you can use fillnull to replace spaces with  "NA"

| rex field=AddtionalData "Business unit:(?<BusinessUnit>[^,]+)"
| rex field=AddtionalData "Location code:(?<Locationcode>[^,]+)"
| rex field=AddtionalData "Job code :(?<Jobcode>[^,]+)"
| fillnull value="NA" BusinessUnit 
| fillnull value="NA" Locationcode 
| fillnull value="NA" Jobcode
| stats count by  BusinessUnit Locationcode Jobcode
| fields - count

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

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

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...