# Convert multiline csv data to a single line csv in filter

**URL:** https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741
**Category:** Logstash
**Created:** [July 10, 2020, 6:22pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741 "2020-07-10T18:22:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [July 10, 2020, 6:22pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/1 "2020-07-10T18:22:25Z")

</div>

Hi All

I have a csv file, which gives me response in multiline csv, i need convert that in a single line csv,

Here is the data

```
"header1","header2","header3"
"col1row1","col2row1","col3row1"
"col1row2","col2row2","col3row2"

```

if i use this below configuration, i get the response like this

```
{"message":"\"col1row2\",\"col2row2\",\"col3row2\"\r"}
{"message":"\"col1row1\",\"col2row1\",\"col3row1\"\r"}

```

my expected result it to get all the value of key "message" combined into a single value.  
You can say its a case of combining all multiline csv value to a single line

```
{"message": "col1row1","col2row1","col3row1"
"col1row2","col2row2","col3row2"}

```

OR

> {"message": "col1row1","col2row1","col3row1"\n  
> "col1row2","col2row2","col3row2"}

This is my conf file

```
input{
	file {
	      path => "/csv_data.csv"
		    sincedb_path => "/sincedb.txt"
          type => "csv"
          start_position => "beginning"
      }
	}
filter {
mutate {
remove_field => ["host","@version","@timestamp","type","path"]
}

		}

	output {
	 file {
	   path => "/test.csv"

	 }
	}

```

Please let me know how we can combine all the value. I also tried checking aggregation filter, but no example usecase found to be a valid for this

Thanks

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 10, 2020, 6:35pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/2 "2020-07-10T18:35:12Z")

</div>

Use a [multiline](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html) codec on the file input.

---

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [July 10, 2020, 8:39pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/3 "2020-07-10T20:39:48Z")

</div>

Hi @Badger , thanks for reply. yes this works well .  
I was trying same in jdbc input, and this was not working there, can you please tell the reason. In both the case the its multiline

I am using this from one of your posts

> codec =\> multiline { pattern =\> "^Spalanzani" negate =\> true what =\> "previous" auto\_flush\_interval =\> 2 }

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 10, 2020, 8:48pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/4 "2020-07-10T20:48:25Z")

</div>

> [@rkhapre](#):
>
> I was trying same in jdbc input, and this was not working there, can you please tell the reason.

The codec option can be [set](https://github.com/logstash-plugins/logstash-input-jdbc/blob/0cee881dcdae5ba75716dacab54aba8da13086b6/lib/logstash/inputs/jdbc.rb#L132) on a jdbc input, but it is ignored.

---

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [July 10, 2020, 8:53pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/5 "2020-07-10T20:53:00Z")

</div>

oh ! that means this cannot be solved. Do you know how we can solve this through aggregation filter or a ruby code?

---

<div class="post-metadata">

### Author: ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)
#### Post date: [July 12, 2020, 1:01pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/6 "2020-07-12T13:01:57Z")

</div>

Hi @Badger, can you provide any suggestion as how we can achieve this for jdbc source

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 12, 2020, 4:16pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/7 "2020-07-12T16:16:24Z")

</div>

If you want to combine rows from the DB then an aggregate filter might be appropriate.

---

<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: [August 9, 2020, 4:16pm UTC](https://discuss.elastic.co/t/convert-multiline-csv-data-to-a-single-line-csv-in-filter/240741/8 "2020-08-09T16:16:26Z")

</div>

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