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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...