Splunk Search

How to read data from a CSV file and put into DB Connect’s query?

ritesh21aggarwa
Engager

Hi,

I want to pull data from a CSV file and put that all data in a SQL query.
For e.g.-
In CSV:
'ABC','DEF','GHI','JKL','MNO'
SQL QUERY:
SELECT emp_name FROM emp WHERE emp_name IN ('ABC','DEF','GHI','JKL','MNO')

I want these “emp_name” get into my SQL query form CSV automatically.

Please help me on this.

Regards,
Ritesh Aggarwal

Tags (1)

jcoates_splunk
Splunk Employee
Splunk Employee

try putting the database query command into a map command. I just messed around with this on DBX2, appears to work well:

state="WA" OR state="CA" | map search="|dbxquery query=\"SELECT%20*%20FROM%20%60northwind%60.%60employees%60%20WHERE%20Region%3D%22$state$%22\" connection=\"dbx-mysql\""

I used this page to url encode: http://meyerweb.com/eric/tools/dencoder/

Forgot to mention -- this will be wicked slow and may make your DBA angry because it's calling that sql command over and over again. If you're going to do this in production, you should just index or lookup your database table and then do the whole job in SPL.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...