I am have trouble trying to extract only lines that are not duplicated and only lines that are only duplicates from a test file. The input file contains both duplicates and non-duplicate lines.
I have created a logging function and I can extract all unique lines from it to a separate file but that includes lines that are duplicates and lines that aren't, I need to separate them.
This is what I have so far;
static void Dupes(string path1, string path2)
{
string log = log.txt;
var sr = new StreamReader(File.OpenRead(path1));
var sw = new StreamWriter(File.OpenWrite(path2));
var lines = new HashSet<int>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
int hc = line.GetHashCode();
if (lines.Contains(hc))
continue;
lines.Add(hc);
sw.WriteLine(line);
}
sw.Close();
}
Ideally this would be in two functions, so they can be called to perform different actions on the output contents.