# Count the number of rows(lines) in a CSV file

**URL:** <https://discuss.elastic.co/t/count-the-number-of-rows-lines-in-a-csv-file/237601>\
**Category:** Logstash\
**Created:** [June 18, 2020, 9:02am UTC](https://discuss.elastic.co/t/count-the-number-of-rows-lines-in-a-csv-file/237601 "2020-06-18T09:02:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![inchirah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inchirah/32/48145_2.png) [@inchirah](https://discuss.elastic.co/u/inchirah)\
**Post date:** [June 18, 2020, 9:02am UTC](https://discuss.elastic.co/t/count-the-number-of-rows-lines-in-a-csv-file/237601/1 "2020-06-18T09:02:12Z")

</div>

Hey guys,

i'm trying to count the number of rows in my csv file (it contain 2631 row) and save it in a variable.  
I used ruby filter but it didn't work so i tried using the metric filter but i get an result that i even don't undrestand.  
Is there any way to count the number of rows using this filter or an other one?  
Here is my code and the result that i get:

```auto
input{

    file{

        path => "C:/Users/SOUMAYA/Desktop/couverture_2g.csv"

        start_position => "beginning"

        sincedb_path => "NUL"

        codec => plain { charset => "CP1252" }

    }

}

filter{

    csv {

        separator => ";"

        columns => [ "Message",

                     "Time",

                     "Distance",

                     "Longitude",

                     "Latitude",

                     "ServRxLevIdle"

                    ]

        convert => {

            "Longitude" => "float"

            "Latitude" => "float"

            "ServRxLevIdle" => "float" 

        } 

    }

    mutate { rename => ["ServRxLevIdle", Contrainte] }

    mutate { add_field => { "Location" => ["%{[Latitude]}","%{[Longitude]}"] } }   

    mutate { convert=> ["Location", "float"] }

    date { match => ["time", "dd MMM yy HH:mm:ss"] }

    metrics {

        meter => "%{@timestamp}_count"  

        add_tag => "metrics"

    }

}

output{

        elasticsearch { 

                    action => "index"

                    hosts => ["http://localhost:9200/"] 

                    index => "monica"

                   

        }

        stdout { codec => rubydebug }

    }

```

The console:

```auto
 },
    "2020-06-18T08:57:46.675Z_count" => {
        "rate_15m" => 0.3659788914920122,
         "rate_1m" => 0.10543885524629079,
         "rate_5m" => 0.30637133534585953,
           "count" => 2
    },
    "2020-06-18T08:57:53.676Z_count" => {
        "rate_15m" => 4.940715035142166,
         "rate_1m" => 1.4234245458249257,
         "rate_5m" => 4.136013027169103,
           "count" => 27
    },
    "2020-06-18T08:57:57.711Z_count" => {
        "rate_15m" => 0.1850339994068403,
         "rate_1m" => 0.06228064478291957,
         "rate_5m" => 0.15837791326735637,
           "count" => 1
    },
    "2020-06-18T08:57:56.533Z_count" => {
        "rate_15m" => 0.5489683372380184,
         "rate_1m" => 0.15815828286943623,
         "rate_5m" => 0.4595570030187892,
           "count" => 3
    },
    "2020-06-18T08:57:36.776Z_count" => {
        "rate_15m" => 0.363951312806147,
         "rate_1m" => 0.09700842985425956,
         "rate_5m" => 0.30130746258186275,
           "count" => 2
    }
}

```

Could you please help me ?

---

<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 16, 2020, 9:02am UTC](https://discuss.elastic.co/t/count-the-number-of-rows-lines-in-a-csv-file/237601/2 "2020-07-16T09:02:19Z")

</div>

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