I have problem where I want to merge 2 large text files together and generate new file with cartesian product of 2 input files. I do know how code would look but not sure in which language to build such a utility. I have windows server and I'm familiar with C#, Shell script.
Note : File1 can be around 20 MB and File2 can contain around 6000 records. So what I want to achieve is Copy 20MB data 6000 times in new file.
Below are smaller examples of how my files would look like
File1
Head-A-AA-AAA
Child-A1-AA1-AAA1
Child-A2-AA2-AAA2
Child-A3-AA3-AAA3
Head-B-BB-BBB
Child-B1-BB1-BBB1
Child-B2-BB2-BBB2
Child-B3-BB3-BBB3
File2
Store1
Store2
Store3
Expected output file
Store1
Head-A-AA-AAA
Child-A1-AA1-AAA1
Child-A2-AA2-AAA2
Child-A3-AA3-AAA3
Head-B-BB-BBB
Child-B1-BB1-BBB1
Child-B2-BB2-BBB2
Child-B3-BB3-BBB3
Store2
Head-A-AA-AAA
Child-A1-AA1-AAA1
Child-A2-AA2-AAA2
Child-A3-AA3-AAA3
Head-B-BB-BBB
Child-B1-BB1-BBB1
Child-B2-BB2-BBB2
Child-B3-BB3-BBB3
Store3
Head-A-AA-AAA
Child-A1-AA1-AAA1
Child-A2-AA2-AAA2
Child-A3-AA3-AAA3
Head-B-BB-BBB
Child-B1-BB1-BBB1
Child-B2-BB2-BBB2
Child-B3-BB3-BBB3
Looking for suggestion if C# code with windows service will serve purpose or I need to use any other tool/utility/scripting?
EDIT : Created below c# code. But it's taking hours to generate 150 GB output file. I'm looking for faster way. I'm taking content from file 1 and copying it for each record in second file
FileInfo[] fi;
List<FileInfo> TodaysFiles = new List<FileInfo>();
string PublishId;
DirectoryInfo di = new DirectoryInfo(@"\\InputPath");
fi = di.GetFiles().Where(file => file.FullName.Contains("TRANSMIT_MASS")).ToArray();
foreach (FileInfo f in fi)
{
string[] tokens = f.Name.Split('_');
if(tokens[2] == DateTime.Now.AddDays(1).ToString("MMddyyyy"))
{
PublishId = tokens[0];
string MACSFile = @"\\OutputPath\\" + PublishId + ".txt";
string path =f.FullName;
string StoreFile = di.GetFiles().Where(file => file.Name.StartsWith(PublishId) && file.Name.Contains("SUBS")).Single().FullName;
using (FileStream fs = File.Open(StoreFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
using (StreamWriter outfile = new StreamWriter(MACSFile))
{
String StoreNumber;
while ((StoreNumber = sr.ReadLine()) != null)
{
Console.WriteLine(StoreNumber);
if (StoreNumber.Length > 5)
{
using (FileStream fsProfile = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bsProfile = new BufferedStream(fsProfile))
using (StreamReader srProfile = new StreamReader(bsProfile))
{
outfile.WriteLine(srProfile.ReadToEnd().TrimEnd());
}
}
}
}
}
}
}