Splunk Search

Dynamic outputlookup file name

Fadom1013
Explorer

Hello ! Need your help splunkers !

I want to append or create a csv for each rows of my query 🙂

I do this for assignate the fields to the file_name  : 

 

| .. query

| foreach *
[
| eval customer_name  = if("<<FIELD>>" = "nom_site", "DATA_".'<<FIELD>>'.".csv", "Error")
| outputlookup  append=true customer_name
]

 

Error in 'outputlookup' command: The lookup table 'customer_name' is invalid. 
(I try with $customer_name$ and $customer_name too).

And I do a second try like this, with a lookup search: 

 

| ... query

| foreach *
[
| eval customer_name  = if("<<FIELD>>" = "nom_site", '<<FIELD>>', "Error")

| outputlookup  append=true [| inputlookup customers.csv | search name=customer_name | eval name_file = "DATA_".name.".csv" | return $name_file)] 
]

 

 Error : Error in 'outputlookup' command: A lookup table name or file name is required.

And finaly, I do with a call of a macro (who contains the precedent lookup search)  : 

 

| ... query

| foreach *
[
| eval customer_name  = if("<<FIELD>>" = "nom_site", '<<FIELD>>', "Error")

| outputlookup  append=true `name_to_csv(customer_name)`
]

 

 
Thanks for your help.
Have a  nice day 🙂

Labels (4)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

I don't understand what you are trying to do.  You say you want to "append or create a csv for each rows", but the foreach command loops over each *field* rather than each row.  To loop over each row, use the map command.

| ... query
| map search="| outputlookup append=true $customer_name$"

What problem are you trying to solve?

---
If this reply helps you, Karma would be appreciated.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...