How to Sort Large CSV files using IO.Streamreader

SURESH0518
SURESH0518 used Ask the Experts™
on
I have large csv file 150 MB file with 5 columns and I would like to sort using Io.streamreader rather than using below command as it very slow on larger files.
import -csv  "c:\temp\test.csv"| sort col1,col2,col3 ,col4,col5 | export-csv "c:\temp\test1.csv"
Is there way to read csv file using  System.IO.StreamReader and sort and write to a new file.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
What happens when you do this?
$csv = import-csv  "c:\temp\test.csv"
$csv | sort col1,col2,col3 ,col4,col5 | export-csv "c:\temp\test1.csv"

Open in new window


When you write "very slow", what do you mean?

What happens when you do this:
import-csv  "c:\temp\test.csv" | sort col5 | export-csv "c:\temp\test5.csv"
import-csv  "c:\temp\test5.csv" | sort col4 | export-csv "c:\temp\test4.csv"
import-csv  "c:\temp\test4.csv" | sort col3 | export-csv "c:\temp\test3.csv"
import-csv  "c:\temp\test3.csv" | sort col2 | export-csv "c:\temp\test2.csv"
import-csv  "c:\temp\test2.csv" | sort col1 | export-csv "c:\temp\test1.csv"

Open in new window


I'm not aware of any sorting capabilities by the IO.StreamReader
Top Expert 2014
Commented:
What are the data types of the five columns?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial