//<a href="https://google.com">Click here</a>
var file_1 = @"F:\Tests\100k.txt";
//Hello from Zenno <a href="https://yandex.ru">Yandex Company</a> this is end of sentence
var file_2 = @"F:\Tests\10kk.txt"; //905mb
//Hello from Zenno <a href="https://google.com">Click here</a> this is end of sentence
var file_3 = @"F:\Tests\Result.txt";
//Регулярка для замены
var regex = new Regex(@"<a\ .*?</a>");
var links = File.ReadLines(file_1, Encoding.UTF8).ToList();
var lines = File.ReadLines(file_2, Encoding.UTF8);
var fs = new FileStream(file_3, FileMode.OpenOrCreate, FileAccess.Write);
var sw = new StreamWriter(fs, Encoding.UTF8);
sw.AutoFlush = true;
foreach(string line in lines)
{
var changedStr = line;
var mCount = regex.Matches(changedStr).Count;
for(int i=0; i< mCount; i++)
{
if(links.Count > 0)
{
var link = links.ElementAt(0);
links.RemoveAt(0);
changedStr = regex.Replace(changedStr, link, i+1);
}
}
sw.WriteLine(changedStr);
}
sw.Close();
fs.Close();