我有一个大的文本文件(3MB,超过50,000行),我希望对它执行一个过滤器。
我发现在Linux机器上很有可能做到这一点,但我不知道如何在windows上过滤它。
我希望将包含指定字符串(例如cake)的每一行复制到新的文本文件中--就像这样简单。我只是不知道。
谢谢:)
发布于 2014-12-23 17:24:48
您可能需要使用带有重定向的MS find命令。例如:
find "cake" yourfile.txt > output.txt您必须在您的大型文本文件所在的目录中执行这一行。
发布于 2014-12-23 17:29:59
使用的C#。
int counter = 0;
string current;
string[] cakeLines;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
System.IO.StreamReader file2 = new System.IO.StreamReader("c:\\test2.txt");
while((current = file.ReadLine()) != null)
{
if ( current.Contains("cake") )
{
cakeLines[counter] = current;
file2.WriteLine(cakeLines[counter]);
}
counter++;
}
file.Close();
file2.Close();https://stackoverflow.com/questions/27625065
复制相似问题