# How to parse a csv file which has some field containing seprator (comma) as-values

**URL:** https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708
**Category:** Logstash
**Created:** [March 16, 2020, 8:09am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708 "2020-03-16T08:09:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Shahid\_Mustafa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahid_mustafa/32/46287_2.png) [@Shahid\_Mustafa](https://discuss.elastic.co/u/Shahid_Mustafa)
#### Post date: [March 16, 2020, 8:09am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/1 "2020-03-16T08:09:59Z")

</div>

sample message - 111,222,333,444,555,val1in6th,val2in6th,777  
The sixth column contains a value consisting of commas (val1in6th,val2in6th is a sample value of 6th column).  
When I use a simple csv filter this message is getting converted to 8 fields. I want to be able to tell the filter that val1in6th,val2in6th should be treated as a single value and placed as the value of 6th column (its okay not to have comma between val1in6th and val2in6th when placed as the output as 6th column).

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [March 16, 2020, 9:38am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/2 "2020-03-16T09:38:43Z")

</div>

Hi there,

are all the other fields always numeric and the 6th field always alphanumeric?

---

<div class="post-metadata">

### Author: ![Shahid\_Mustafa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahid_mustafa/32/46287_2.png) [@Shahid\_Mustafa](https://discuss.elastic.co/u/Shahid_Mustafa)
#### Post date: [March 16, 2020, 9:54am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/3 "2020-03-16T09:54:40Z")

</div>

No, all fields are string. This is just an example. I can't paste the original values here because of company restrictions.

---

<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: [March 16, 2020, 5:19pm UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/4 "2020-03-16T17:19:14Z")

</div>

If you want to have a comma in a field of a CSV then the entire field has to be in double quotes.

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [March 17, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/5 "2020-03-17T08:26:20Z")

</div>

Exactly. One way or another, I guess your best shot is to edit your document upstream (you either choose a different type of separator or you replace the commas in that field with another symbol or you surround that field with double quotes as Badger suggested).

---

<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: [April 14, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-to-parse-a-csv-file-which-has-some-field-containing-seprator-comma-as-values/223708/6 "2020-04-14T08:26:27Z")

</div>

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