Sort a CSV File by a Specific Column

Problem description & analysis

Below is CSV file csv.csv:

1001,Name1,9

1005,Name2,20

1007,Name3,14

The CSV file is unordered by the third column. Now we are trying to sort the file by that column. Below is the desired result:

1001,Name1,9

1007,Name3,14

1005,Name2,20

Solution

Write the following script p1.dfx in esProc:

A

1

=file("csv.csv").import@c().sort(#3)

2

=file("result.csv").export@c(A1)

Explanation:

A1   Import the CSV file as a table sequence and sort it by the third column.

A2  Export A1’s result to result.csv.

Q & A Collection

https://stackoverflow.com/questions/61951573/how-to-sort-a-csv-file-by-a-specific-column-in-java