Splunk Search

Null value for each column data

jhayIV
Engager

Is there a way I can use the foreach function to create a variables that will give me a 1 value for each null value ?

Here is how I would do it for cores: eval nullcores=if(isnull(Cores),1,0)

index=#### sourcetype=#### | Table Name,Cores,DNS_Host_Name,Domain,IsVirtual,NumberOfProcessors,OS,Owner_Contact,ProdCat1,ProdCat2,ProdCat3,Region,Serial_Number,Site,SiteGroup,SystemRole,SystemStatus,Total_Managedby,Total_Ownedby,Total_Patchedby,Total_Physical_Memory,Total_Applications|

Tags (2)
0 Karma

DalJeanis
Legend

Yes, you can do that easily - some methods are after the bar -- but the question you are asking indicates you are probably trying to overcomplicate your life.

Please step back and describe your use case. What information are you trying to create, and what will you do with that information?


Use this if you want one field per field...

  | foreach (your list of fields)  [eval null<<field>>=if(isnull(<<field>>),1,0)"]

Use this if you want one field total...

  | eval addupnulls=0
  | foreach (your list of fields)  [eval addupnulls=addupnulls+if(isnull(<<field>>),1,0)"]
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Expanding on your example gets a foreach command like this.

index=#### sourcetype=#### | foreach * [eval null<<FIELD>>=if(isnull(<<FIELD>>),1,0)] | table Name,Cores,DNS_Host_Name,Domain,IsVirtual,NumberOfProcessors,OS,Owner_Contact,ProdCat1,ProdCat2,ProdCat3,Region,Serial_Number,Site,SiteGroup,SystemRole,SystemStatus,Total_Managedby,Total_Ownedby,Total_Patchedby,Total_Physical_Memory,Total_Applications null*
---
If this reply helps you, Karma would be appreciated.
0 Karma

somesoni2
Revered Legend

You can try fillnull command like this

index=#### sourcetype=#### | table Name,Cores,DNS_Host_Name,Domain,IsVirtual,NumberOfProcessors,OS,Owner_Contact, ProdCat1,ProdCat2,ProdCat3,Region,Serial_Number,Site,SiteGroup,SystemRole,SystemStatus, Total_Managedby,Total_Ownedby,Total_Patchedby,Total_Physical_Memory,Total_Applications | fillnull value=1

OR foreach command like this

index=#### sourcetype=#### | table Name,Cores,DNS_Host_Name,Domain,IsVirtual,NumberOfProcessors,OS,Owner_Contact, ProdCat1,ProdCat2,ProdCat3,Region,Serial_Number,Site,SiteGroup,SystemRole,SystemStatus, Total_Managedby,Total_Ownedby,Total_Patchedby,Total_Physical_Memory,Total_Applications | foreach * [eval <<FIELD>>=coalesce(<<FIELD>>,1)]
0 Karma
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!

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

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...