All Apps and Add-ons

How to assign a variable as a result of a search?

New2Splunk
Explorer

I have a very watered down search that pulls a string from a CSV file:

source="FILE.csv" host="HOSTSERVER" sourcetype="csv" "COLUMN NAME WITH SPACES IN CSV"="123" | table "COLUMN NAME WITH SPACES IN CSV"

Running this search returns a string as expected.

I would like to assign this value to a variable. The eval statement below is part of a larger search that builds a database query used in a dbxquery search:

eval STRINGBACK=[search source="FILE.csv" host="HOSTSERVER" sourcetype="csv" "COLUMN NAME WITH SPACES IN CSV"="123" | table "COLUMN NAME WITH SPACES IN CSV"]

When I try to run it, I get the error "Error in 'eval' command: Fields cannot be assigned a boolean result. Instead, try if([bool expr], [expr], [expr]). "

I did a tostring() on the STRINGBACK eval to see what is thought was coming back from the search, and it is "FALSE". I'm guessing I'm doing something pretty simple and foolish here to mess things up. Can anyone let me know what I am doing wrong? Thanks!

0 Karma

lguinn2
Legend

In an eval statement, strings have double-quotes ("string") and field names have single quotes ('field name'). So do this:

 eval STRINGBACK=[search source="FILE.csv" host="HOSTSERVER" sourcetype="csv" 'COLUMN NAME WITH SPACES IN CSV'="123" | table "COLUMN NAME WITH SPACES IN CSV"]

Or better

rename "COLUMN NAME WITH SPACES IN CSV" as new_name

and then just use the new name everywhere.

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...