Getting Data In

How to combine multiple searches and output results into one CSV file?

mendesjo
Path Finder

Here is example query..

index=A host=host1 | stats count by host 
| index=B sourcetype=s1 | dedup host | table host 
| index=C sourcetype=s2 | dedup host | table host 
| outputcsv output_file_name

Individually, these queries work, but in a perfect world I'd like to run the queries as one to produce the outputs into one single CSV. Possible? Running the searches separately and appending to same CSV file is fine also.

0 Karma
1 Solution

gokadroid
Motivator

how about using append

index=A host=host1 | stats count by host 
|append [ search  index=B sourcetype=s1 | dedup host | table host ]
|append [ search  index=C sourcetype=s2 | dedup host | table host ]
| outputcsv output_file_name

For details on append see here

View solution in original post

gokadroid
Motivator

how about using append

index=A host=host1 | stats count by host 
|append [ search  index=B sourcetype=s1 | dedup host | table host ]
|append [ search  index=C sourcetype=s2 | dedup host | table host ]
| outputcsv output_file_name

For details on append see here

mendesjo
Path Finder

Thank you for the suggestion, wow that works!

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try these

(index=A host=host1) OR (index=B sourcetype=s1) OR (index=C sourcetype=s2)
| stats count by host | outputcsv output_file_name

If you don't want count field for index=B and index=C, try this

(index=A host=host1) OR (index=B sourcetype=s1) OR (index=C sourcetype=s2)
| stats count by host | eval count=if(host="host1",count,null())| outputcsv output_file_name

mendesjo
Path Finder

Thank you for the suggestion, you are correct with your 2nd suggestion I didn't want to count them and I find the append command easier to work with. Thanks again, totally forgot that OR will do it as well. Thanks again!

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