# Handling Unordered CSV

**URL:** https://community.seqera.io/t/handling-unordered-csv/1662
**Category:** Tips & Tricks
**Tags:** nextflow
**Created:** [January 26, 2025, 3:18pm UTC](https://community.seqera.io/t/handling-unordered-csv/1662 "2025-01-26T15:18:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Firas\_Zemzem](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/firas_zemzem/32/892_2.png) [@Firas\_Zemzem](https://community.seqera.io/u/Firas_Zemzem)
#### Post date: [January 26, 2025, 3:18pm UTC](https://community.seqera.io/t/handling-unordered-csv/1662/1 "2025-01-26T15:18:52Z")

</div>

Ever been frustrated when your input CSV file isn’t ordered, and you want to use it as it is without manually modifying it? A better way ; you can leverage toSortedList and flatMap operators to process your raw input directly .

* * *

just used this snippet to inspect my channel

 ![post.nf](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/d/df693d19f57c7baa6a2e2a3fba9b105fde8be027.png)  
output :  
 ![runned post.nf](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/c/cb6da9ea260607052cab403e352768d293fb1df0.png)

* * *

1️⃣ Use [toSortedList](https://www.nextflow.io/docs/latest/reference/operator.html#tosortedlist) to sort the raw input dynamically based on your desired key(s).

2️⃣ Follow it up with [flatMap](https://www.nextflow.io/docs/latest/reference/operator.html#flatmap) to transform the sorted data into a flat, streamlined structure for further processing.

 ![modified code](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/4/4c7150cd799ca72762676e1c5d47b3632118cb43.png)

**result: sorted csv**

 ![output](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/4/4e23879b22c59ec4ce9401f9e305194a3c54257b.png)
