# Get the field count of a csv file

**URL:** <https://discuss.elastic.co/t/get-the-field-count-of-a-csv-file/124161>\
**Category:** Logstash\
**Created:** [March 15, 2018, 6:52pm UTC](https://discuss.elastic.co/t/get-the-field-count-of-a-csv-file/124161 "2018-03-15T18:52:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfseth](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@pfseth](https://discuss.elastic.co/u/pfseth)\
**Post date:** [March 15, 2018, 6:52pm UTC](https://discuss.elastic.co/t/get-the-field-count-of-a-csv-file/124161/1 "2018-03-15T18:52:01Z")

</div>

Sample CSV file

> 2018-03-05 21:29:31 -0500|188c9263-2519-4a8d-825c-4605c53b720e|email|1000|0|7702831801|start|89029287801|1273721801|end
> 
> 2018-03-05 21:23:10 -0500|23k8w23y-27k3-293s-le22-825c29l23us2|fax|21000|0|2389231|282830282|92903-109281-3628|89029287801|1273721801|22po39|starttime|endtime|success

Which filter can get the field count

The first line has 10 fields & the second has 15 fields

---

<div class="post-metadata">

**Author:** ![pfseth](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@pfseth](https://discuss.elastic.co/u/pfseth)\
**Post date:** [March 16, 2018, 7:33pm UTC](https://discuss.elastic.co/t/get-the-field-count-of-a-csv-file/124161/2 "2018-03-16T19:33:47Z")

</div>

Not familiar with ruby, however managed to get the field count using the ruby filter

```
filter {

   ruby { code => 'event.set("[@metadata][field_count]", event.get("message").split("|").count())' }
 }
```

---

<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 13, 2018, 7:33pm UTC](https://discuss.elastic.co/t/get-the-field-count-of-a-csv-file/124161/3 "2018-04-13T19:33:50Z")

</div>

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