I have 2 files, both have a different amount of length in lines, however, there is a high probability that they share one value to each other that reside in different columns, example:
File1.csv = A,B,C,D,E (this file is 20 lines long)
File2.csv = A,B,D,C (no E and this file is 10 lines long)
How can I see if the value in the 3rd column of File1 is the same as the value in column 4 of File2, then also append file2's column 4 value to the end of each line in File1 (on match of eachother) and also not letting the loop end prematurely because File2 has less lines than File1?
First off, I think I'll need to look at setting up a linq statement similar to
var file1lines = File.ReadLines(file1)
.Select(line => line.Split(','))
.Where(item => item.All(part => !string.IsNullOrWhiteSpace(part)))
.ToList();
var file2lines = File.ReadLines(file2)
.Select(line => line.Split(','))
.Where(item => item.All(part => !string.IsNullOrWhiteSpace(part)))
.ToList();
var result = from a in file1lines.AsParallel()
from b in file2lines.AsParallel()
where a[2] == b[3]
select new { a, b, };
using (StreamReader checkfiles = new StreamReader(file1)
{
foreach (var x in result)
{
// ...
}
}
Or would I even want to use a streamreader? or would I want 2 to open up both files so I can read them together (although I believe Linq accomplish this for me using .readlines) Am I just overcomplicating this whole scenario?
Thanks for any help or advice. I can't seem to wrap my head around what I want to do with the programming skills I currently have. It can't be that hard, so I'm missing something.