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