Delete specific contents of file in blob container
I have log files in container, I want to search a list of strings in the log file and delete the specific record of the file matching with the string and save the file in same container with same name.
Say the log file is
abc.txt
10/20/2020 12:00:00 this line contains log
10/21/2020 12:00:00 this line contains numbers
10/21/2020 12:00:00 this line contains string
so I want to search for strings (numbers, string) and eliminate those records and save abc.txt in same container so that it will look like
abc.txt
10/20/2020 12:00:00 this line contains log
I am trying with stremreader and streawriter, but it is not working
using (StreamReader reader = new StreamReader(longestFile.Open()))
{
using (StreamWriter writer = new StreamWriter(text.Open()))
{
while((line = reader.ReadLine()) != null)
{
bool res = true;
// Look for text to remove
foreach(string s in linesToRemove)
{
if(line.Contains(s))
{
res = false;
}
}
if(res)
{
// Keep lines that does not match
writer.WriteLine(line);
}
}
}
}