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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...