我的csv文件有14列和~800.000行。我必須按照第10欄排序,然後按第3欄排序。 我使用下面的代碼,但種種僅10列如何用c中的兩列對csv文件進行排序#
string filePath = "D:\\csv.csv";
string[] lines = File.ReadAllLines(filePath, Encoding.Default);
var data = lines.Skip(1);
var sorted = data.Select(line => new
{
SortKey = Int32.Parse(line.Split(';')[9]),
Line = line
}
).OrderBy(x => x.SortKey).Select(x => x.Line);
File.WriteAllLines("D:\\sortedCsv.csv", lines.Take(1).Concat(sorted), Encoding.Default);
我的CSV喜歡
- COL1; col2; col3; ......; col10; ...
- abc; fds; 123456; ....; 123; ..
- def; dsa; 12435; ...... 124; ..
它的作品謝謝你。其實這很容易。 – eneseto 2014-10-10 09:37:58