我希望将IIS日志导入到SQL中,以便使用Bulk Insert进行报告,但是注释行(以#开头的那些行)会导致问题,因为这些行的字段数与数据行的字段数不同。
如果我手动删除注释,我就可以执行大容量插入。
是否有一种方法可以在排除基于匹配的行的同时执行批量插入,例如:任何以"#“开头的行。
谢谢。
发布于 2012-10-05 12:24:19
微软有一个名为"PrepWebLog“http://support.microsoft.com/kb/296093的工具,它可以剔除这些散列/井号字符,但是我现在运行它(使用PowerShell脚本处理多个文件),发现它的性能慢得让人无法忍受。
我想如果我写一个C#程序(或者甚至是宏)会更快。
更新: PrepWebLog刚刚在我身上崩溃了。我会避免的。
更新#2,我查看了PowerShell的Get-Content和Set-Content命令,但不喜欢其语法和可能的性能。所以我写了这个小的C#控制台应用:
if (args.Length == 2)
{
string path = args[0];
string outPath = args[1];
Regex hashString = new Regex("^#.+\r\n", RegexOptions.Multiline | RegexOptions.Compiled);
foreach (string file in Directory.GetFiles(path, "*.log"))
{
string data;
using (StreamReader sr = new StreamReader(file))
{
data = sr.ReadToEnd();
}
string output = hashString.Replace(data, string.Empty);
using (StreamWriter sw = new StreamWriter(Path.Combine(outPath, new FileInfo(file).Name), false))
{
sw.Write(output);
}
}
}
else
{
Console.WriteLine("Source and Destination Log Path required or too many arguments");
}这很快。
https://stackoverflow.com/questions/11803765
复制相似问题