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

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...