# CSV as input and CSV as output

**URL:** <https://discuss.elastic.co/t/csv-as-input-and-csv-as-output/175160>\
**Category:** Logstash\
**Created:** [April 3, 2019, 10:14am UTC](https://discuss.elastic.co/t/csv-as-input-and-csv-as-output/175160 "2019-04-03T10:14:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmk1995](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mmk1995](https://discuss.elastic.co/u/mmk1995)\
**Post date:** [April 3, 2019, 10:14am UTC](https://discuss.elastic.co/t/csv-as-input-and-csv-as-output/175160/1 "2019-04-03T10:14:40Z")

</div>

Dear All,

I am new to logstash and I am trying to input a .csv file to logstash and output it also as a .csv format for my testing.  
However, I find that the output .csv is not ordered row by row as the input .csv file. The order is somehow randomized even I specified start\_position is beginning.  
Moreover, since the input .csv come with the field name in 1st row, logstash regarded it as a document rather than field name, this frustrated me.  
It would be glad if someone could solve my problem. Thank you in advance.

> ```
> input {
> file {
> path => "/home/elk/logstash-6.5.4/input_data/M10d-splunk-wk.csv"
> start_position => "beginning"
> sincedb_path => "/dev/null"
> }
> }
> filter {
> csv {
> separator => ","
> columns => ["TimeStamp","username","User Agent","Region","Source IP","altemail","countrycode","phone","acctype","kuemail"]
> autodetect_column_names => true
> autogenerate_column_names => true
> }
> 
> fingerprint {
> method => "SHA256"
> source => ["username"]
> }
> 
> mutate { add_field => { 'username_key' => "%{fingerprint}" 'username_value' => "%{username}" } }
> mutate { replace => { "username" => "%{fingerprint}" } }
> 
> fingerprint {
> method => "SHA256"
> source => ["phone"]
> }
> 
> mutate { add_field => { 'phone_key' => "%{fingerprint}" 'phone_value' => "%{phone}" } }
> mutate { replace => { "phone" => "%{fingerprint}" } }
> }
> output {
> csv {
> fields => ["TimeStamp","username","User Agent","Region","Source IP","altemail","countrycode","phone","acctype","kuemail"]
> path => "/home/elk/logstash-6.5.4/input_data/a.csv"
> }
> csv {
> fields => ["username_key","username_value","phone_key","phone_value"]
> path => "/home/elk/logstash-6.5.4/input_data/b.csv"
> }
> }
> 
> ```

---

<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:** [April 3, 2019, 12:53pm UTC](https://discuss.elastic.co/t/csv-as-input-and-csv-as-output/175160/2 "2019-04-03T12:53:56Z")

</div>

> [@mmk1995](#):
>
> However, I find that the output .csv is not ordered row by row as the input .csv file. The order is somehow randomized even I specified start\_position is beginning.

That is working as expected. If you add "--pipeline.workers 1" to the command line to make logstash single-threaded that may help, but logstash does not guarantee ordering.

---

<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:** [May 1, 2019, 12:54pm UTC](https://discuss.elastic.co/t/csv-as-input-and-csv-as-output/175160/3 "2019-05-01T12:54:20Z")

</div>

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