Question

I have a really large csv file and want to sort them external.
The problem is that i need several sorting orders and a separator which I can specify.

I've searched a while and found out, that I need to use the window sort command.
But I didn't find anything. How I can specify the separator of the sorting order?

All I found was a solution on unix ("sort --field-separator=';' --key=2,1,3") but it looks like there is no equivalent on windows.

Do you have any idea how i can solve the problem without implementing my own sort algorithm?
(By the way I'm using C#)

Was it helpful?

Solution

Use windows Power-Shell. Command you are interested in is:

Import-CSV [your file] | Sort-Object [column header].

The result will be sorted by the "column header". For more elaborated sort use:

Import-CSV [your file] | Sort-Object [first sort header] [second sort header].

For example, these are my data:

A,B,C,D 1000,1,a,2 99,2,bs,3 1000,3,g,4 66,2,a,3 20,16,3,b 1000,7,c,4 99,1,lz,4

This command: Import-CSV .\test.csv | Sort-Object C will give following result:

A B C D - - - - 20 16 3 b 66 2 a 3 1000 1 a 2 99 2 bs 3 1000 7 c 4 1000 3 g 4 99 1 lz 4

Here is a link that explains it in more details:

http://blogs.technet.com/b/heyscriptingguy/archive/2008/02/12/how-can-i-use-windows-powershell-to-sort-a-csv-file.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top