# Logstash csv - Filters only rows with specific column count

**URL:** <https://discuss.elastic.co/t/logstash-csv-filters-only-rows-with-specific-column-count/213569>\
**Category:** Logstash\
**Created:** [January 2, 2020, 12:24pm UTC](https://discuss.elastic.co/t/logstash-csv-filters-only-rows-with-specific-column-count/213569 "2020-01-02T12:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lubos\_Marek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lubos_marek/32/59043_2.png) [@Lubos\_Marek](https://discuss.elastic.co/u/Lubos_Marek)\
**Post date:** [January 2, 2020, 12:24pm UTC](https://discuss.elastic.co/t/logstash-csv-filters-only-rows-with-specific-column-count/213569/1 "2020-01-02T12:24:47Z")

</div>

Hello,  
I have a log file (\*.csv) with this specifific structure  
datetime;level; statuscode; message

Sometimes missing the "statuscode" and that row has only 3 columns (datetime;level;message).

Can I somehow skip rows with 3 columns?

```
input {

  file {

    path => ["/usr/share/logstash/data1/*.csv"]

    start_position => "beginning"

    sincedb_path => "/dev/null"

  }

}

filter {

  csv {

    separator => ";"

    columns => ["datetime", "level", "statuscode", "message"]

  }

}

output {

  elasticsearch {

    hosts => ["http://host.docker.internal:9200"]

    index => "log"

  }

}
```

---

<div class="post-metadata">

**Author:** ![rugenl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rugenl/32/12887_2.png) [@rugenl](https://discuss.elastic.co/u/rugenl)\
**Post date:** [January 2, 2020, 1:08pm UTC](https://discuss.elastic.co/t/logstash-csv-filters-only-rows-with-specific-column-count/213569/2 "2020-01-02T13:08:51Z")

</div>

Something like this filter might work:

```
  ruby {
    code => 'if event.get("[message]).count(\";\") < 3
      event.cancel
    end'
  }

```

"Might" because some of the examples I used were the "old" ruby syntax before we needed to use "event.get".

The idea is that if there are less than 3 separator chars, there aren't 4 columns.

That CSV should have ";;" to designate the statuscode is null instead of this format.

---

<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:** [January 30, 2020, 1:08pm UTC](https://discuss.elastic.co/t/logstash-csv-filters-only-rows-with-specific-column-count/213569/3 "2020-01-30T13:08:55Z")

</div>

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