# Save arrays as csv output put

**URL:** <https://discuss.elastic.co/t/save-arrays-as-csv-output-put/162559>\
**Category:** Logstash\
**Created:** [January 1, 2019, 9:37am UTC](https://discuss.elastic.co/t/save-arrays-as-csv-output-put/162559 "2019-01-01T09:37:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Hettiarachchi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Manoj\_Hettiarachchi](https://discuss.elastic.co/u/Manoj_Hettiarachchi)\
**Post date:** [January 1, 2019, 9:37am UTC](https://discuss.elastic.co/t/save-arrays-as-csv-output-put/162559/1 "2019-01-01T09:37:00Z")

</div>

Hello,

In my system, I input a very long log using filebeat ( has about 3000 characters in a single log line)  
I need to use logstash to save this log in a csv file.  
I need to save the log as multiple comma-separated columns by splitting in to separate 300 character elements.  
I was able to create the needed array with a ruby code.  
But when I use the csv output plugin to print the array into separate csv files it is not working properly. The whole array is printed in a single csv column.

My Code is as follows.

```
input {
    beats {
      host => "localhost"
      port => 5043
    }
}

filter {
 ruby {      
        code => "
        def chunk(string, size)
          string.scan(/.{1,#{size}}/)
        end
        vararr = chunk(event.get('[message]'),300)
        event.set('responsearr', vararr)"
  }
  mutate { remove_field => ["message"] } 
}

output {
  csv {
    path => "/var/csv_reports/test.csv"
    fields => ["responsearr"]
  }
}

```

what am I doing wrong ?

---

<div class="post-metadata">

**Author:** ![Manoj\_Hettiarachchi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Manoj\_Hettiarachchi](https://discuss.elastic.co/u/Manoj_Hettiarachchi)\
**Post date:** [January 18, 2019, 6:41am UTC](https://discuss.elastic.co/t/save-arrays-as-csv-output-put/162559/2 "2019-01-18T06:41:38Z")

</div>

Hello,

I tried many approaches and was unable to find a solution.  
So I manually edited the "logstash-output-csv" repo and added the customized plugin.  
Now my requirement is a completed successfully.

Thanks

---

<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:** [February 15, 2019, 6:41am UTC](https://discuss.elastic.co/t/save-arrays-as-csv-output-put/162559/3 "2019-02-15T06:41:58Z")

</div>

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