# CSV file with different record types

**URL:** <https://discuss.elastic.co/t/csv-file-with-different-record-types/24882>\
**Category:** Logstash\
**Created:** [July 3, 2015, 6:10pm UTC](https://discuss.elastic.co/t/csv-file-with-different-record-types/24882 "2015-07-03T18:10:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khoa\_Nguyen1](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khoa\_Nguyen1](https://discuss.elastic.co/u/Khoa_Nguyen1)\
**Post date:** [July 3, 2015, 6:10pm UTC](https://discuss.elastic.co/t/csv-file-with-different-record-types/24882/1 "2015-07-03T18:10:24Z")

</div>

Our files are in CSV format but each line can be of a different record type. For example:

f1,f2,f3  
g1,g2,g3,g4,g5  
h1,h2,h3,h4

Record type can be determined by examining the value of the first field. How do I write a CSV filter for this?

---

<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:** [July 3, 2015, 8:13pm UTC](https://discuss.elastic.co/t/csv-file-with-different-record-types/24882/2 "2015-07-03T20:13:16Z")

</div>

You could use a conditional to take a peek at the line and based on that choose between different csv filters.

```
if [message] =~ /^some pattern/ {
  csv {
    ...
  }
} else if [message] =~ /^other pattern/ {
  csv {
    ...
  }
}
```

---

<div class="post-metadata">

**Author:** ![Khoa\_Nguyen1](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khoa\_Nguyen1](https://discuss.elastic.co/u/Khoa_Nguyen1)\
**Post date:** [July 3, 2015, 8:27pm UTC](https://discuss.elastic.co/t/csv-file-with-different-record-types/24882/3 "2015-07-03T20:27:21Z")

</div>

Thanks for the elegant solution. I will give this a try

---

<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 6, 2017, 5:35am UTC](https://discuss.elastic.co/t/csv-file-with-different-record-types/24882/4 "2017-07-06T05:35:32Z")

</div>


