# How to use multiple csv files in logstash ,

**URL:** <https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200>\
**Category:** Logstash\
**Created:** [June 21, 2017, 5:50am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200 "2017-06-21T05:50:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijjun123](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vijjun123](https://discuss.elastic.co/u/vijjun123)\
**Post date:** [June 21, 2017, 5:50am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/1 "2017-06-21T05:50:53Z")

</div>

I want to use multiple csv files in logstash hence please guide me . now using single csv file as per the below.

remaining file names are different ex : file1,file2,file3

input {  
file {  
path =\> "/tmp/AWSDiscoverynew.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter {  
csv {  
separator =\> ","  
columns =\> ["Region Name","Endpoint"]  
}  
}  
output {  
elasticsearch {  
hosts =\> ""  
index =\> "data-index"  
}  
stdout {}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 21, 2017, 6:14am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/2 "2017-06-21T06:14:11Z")

</div>

Use can e.g. use different file inputs that each assign different types and then you can use conditionals to apply different filters and outputs to each kind of file.

[https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html)

---

<div class="post-metadata">

**Author:** ![vijjun123](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vijjun123](https://discuss.elastic.co/u/vijjun123)\
**Post date:** [June 21, 2017, 6:24am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/3 "2017-06-21T06:24:51Z")

</div>

Hi Magnus ,

Thanks alot for help,and not able to pass the values as per the below.

input  
{  
file  
{  
path =\> "/tmp/AWSDiscoverynew.csv"  
start\_position =\> "beginning"  
#sincedb\_path =\> "/user/somelocation/.sincedb"  
}  
file  
{  
path =\> "/tmp/AWSDiscoveryTest.csv"  
start\_position =\> "beginning"

# sincedb\_path =\> "/user/somelocation/.sincedb"

}  
}  
filter {  
if [path] == "/tmp/AWSDiscoverynew.csv"  
{  
csv {  
columns =\> [A,B,C,D]  
separator =\> ","  
}  
}  
else if [path] == "/tmp/AWSDiscoveryTest.csv"  
{  
csv {  
columns =\> [A,E,F,G]  
separator =\> ","  
}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 21, 2017, 6:31am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/4 "2017-06-21T06:31:50Z")

</div>

So what happens? What does an example event look like when Logstash is done with it? Use a `stdout { codec => rubydebug }` output.

---

<div class="post-metadata">

**Author:** ![vijjun123](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vijjun123](https://discuss.elastic.co/u/vijjun123)\
**Post date:** [June 21, 2017, 8:20am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/5 "2017-06-21T08:20:27Z")

</div>

Hi Magnus ,  
using the below and got the error

fetched an invalid config {:config=\>"input\n{\nfile\n{\npath =\> "/tmp/AWSDiscoverynew.csv"\nstart\_position =\> "beginning"\n}\nfile\n {\npath =\> "/tmp/AWSDiscoveryTest.csv"\nstart\_position =\> "beginning"\n}\n}\nfilter {\nif [path] == "/tmp/AWSDiscoverynew.csv"\n{\ncsv {\n columns =\> ["Region Name","Endpoint"]\n separator =\> ","\n}\n}\nelse if [path] == "/tmp/AWSDiscoveryTest.csv" \n{\ncsv {\n columns =\> ["VpcId","State","CidrBlock","DhcpOptionsId","Tags","InstanceTenancy","IsDefault"]\nseparator =\> ","\n}\n}\noutput {\n elasticsearch {\n hosts =\> ""\n index =\> "data-index"\n }\nstdout { codec =\> rubydebug }\n}\n\n", :reason=\>"Expected one of #, =\> at line 30, column 18 (byte 490) after filter {\nif [path] == "/tmp/AWSDiscoverynew.csv"\n{\ncsv {\n columns =\> ["Region Name","Endpoint"]\n separator =\> ","\n}\n}\nelse if [path] == "/tmp/AWSDiscoveryTest.csv" \n{\ncsv {\n columns =\> ["VpcId","State","CidrBlock","DhcpOptionsId","Tags","InstanceTenancy","IsDefault"]\nseparator =\> ","\n}\n}\noutput {\n elasticsearch ", :level=\>:error}

input  
{  
file  
{  
path =\> "/tmp/AWSDiscoverynew.csv"  
start\_position =\> "beginning"  
}  
file  
{  
path =\> "/tmp/AWSDiscoveryTest.csv"  
start\_position =\> "beginning"  
}  
}  
filter {  
if [path] == "/tmp/AWSDiscoverynew.csv"  
{  
csv {  
columns =\> ["Region Name","Endpoint"]  
separator =\> ","  
}  
}  
else if [path] == "/tmp/AWSDiscoveryTest.csv"  
{  
csv {  
columns =\> ["VpcId","State","CidrBlock","DhcpOptionsId","Tags","InstanceTenancy","IsDefault"]  
separator =\> ","  
}  
}  
output {  
elasticsearch {  
hosts =\> ""  
index =\> "data-index"  
}  
stdout { codec =\> rubydebug }

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 21, 2017, 8:25am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/6 "2017-06-21T08:25:26Z")

</div>

It looks like you're not closing the filter block before you begin your output block. Also, you're not closing your output block.

---

<div class="post-metadata">

**Author:** ![vijjun123](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vijjun123](https://discuss.elastic.co/u/vijjun123)\
**Post date:** [June 21, 2017, 9:47am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/7 "2017-06-21T09:47:31Z")

</div>

Please find the below config file and correct if anything wrong

input  
{  
file  
{  
path =\> "/tmp/AWSDiscoverynew.csv"  
start\_position =\> "beginning"  
}  
file  
{  
path =\> "/tmp/AWSDiscoveryTest.csv"  
start\_position =\> "beginning"  
}  
}  
filter {  
if [path] == "/tmp/AWSDiscoverynew.csv"  
{  
csv {  
columns =\> ["A","B","C","D"]  
separator =\> ","  
}  
}  
}  
else if [path] == "/tmp/AWSDiscoveryTest.csv" or [path] == "/tmp/AWSDiscoverytest2.csv"  
}  
{  
csv {  
columns =\> ["A","B","C","D","E","F","G"]  
separator =\> ","  
}  
}  
output {  
elasticsearch {  
hosts =\> "http://"  
index =\> "data-index"  
}  
stdout {}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 21, 2017, 11:12am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/8 "2017-06-21T11:12:16Z")

</div>

The `hosts` option in your elasticsearch output is obviously incorrect but otherwise it should work. However, having this kind of direct dependencies to filenames is a bad idea. Prefer setting the type or some other field in each file input and adjust your conditionals.

---

<div class="post-metadata">

**Author:** ![vijjun123](https://avatars.discourse-cdn.com/v4/letter/v/cab0a1/32.png) [@vijjun123](https://discuss.elastic.co/u/vijjun123)\
**Post date:** [June 21, 2017, 11:56am UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/9 "2017-06-21T11:56:56Z")

</div>

Thanks for the update,

I user the below log fie and got the below error,could you please check

The given configuration is invalid. Reason: Expected one of #, input, filter, output at line 28, column 1 (byte 351) after {:level=\>:fatal}

input  
{  
file  
{  
path =\> "/tmp/AWSDiscoverynew.csv"  
start\_position =\> "beginning"  
}  
file  
{  
path =\> "/tmp/AWSDiscoveryTest.csv"  
start\_position =\> "beginning"  
}  
file  
{  
path =\> "/tmp/AWSDiscoverytest2.csv"  
start\_position =\> "beginning"  
}  
}  
filter {  
if [path] == "/tmp/AWSDiscoverynew.csv"  
{  
csv {  
columns =\> ["A","B","C","D"]  
separator =\> ","  
}  
}  
}  
else if [path] == "/tmp/AWSDiscoveryTest.csv" or [path] == "/tmp/AWSDiscoverytest2.csv"  
}  
{  
csv {  
columns =\> ["A","B","C","D","E","F","G"]  
separator =\> ","  
}  
}  
output {  
elasticsearch {  
hosts =\> "http:localhost//"  
index =\> "data-index"  
}  
stdout {}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 21, 2017, 12:10pm UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/10 "2017-06-21T12:10:25Z")

</div>

You have too many braces before `else if [path]`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 19, 2017, 12:10pm UTC](https://discuss.elastic.co/t/how-to-use-multiple-csv-files-in-logstash/90200/11 "2017-07-19T12:10:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
