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!

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, ...