I am trying to sort a txt file through 3rd column in c#. I can see 4 rows beneath my columns but the text file contains a lot more rows. I also need to get one more functionality working and that is removing duplicate data from the display. {If data in the first and second column is the same as another row then remove one instance from the display. data is case sensitive i.e. broc is not the same as BRoc}. Help appreciated. My code is as follows. Please note that the txt file is a TSV and not a CSV.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var records = (from l in File.ReadAllLines(@"d:\data\542112107\Desktop\project 1\Project1\Project1\bin\Debug\instance_test.txt")
let pieces = l.Split('\t')
select new { Col1 = pieces[0], Col2 = pieces[1], Col3 = pieces[2], Col4 = pieces[3] })
.Skip(1)
.Distinct()
.OrderBy(c => c.Col3);
for (int i = 0; i < 99; i++)
{
} foreach (var r in records)
{ Console.WriteLine("{0}, {1}, {2},{3}", r.Col1, r.Col2, r.Col3, r.Col4); }
Console.WriteLine();
Console.WriteLine("Done");
Console.ReadLine();
}
}
}
Here is the sample input:(\n is new line)
Heading 1 Heading 2 Heading3 Heading 4 ascvad3124 adfdasfData asasffasf adsfasfasdf asf123134Data dasfasdfdasfData Dasfasfata asdfasdfadsf 123123fData asdfdasfsData asdfasdfasdf sadvsdfdaf