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!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...