[英]How can I search and extract lines which contain a specific string in a large text file on Windows?
I have a large text file (3MB over 50,000 lines) and I would wish to perform a filter on it.我有一个大文本文件(3MB 超过 50,000 行),我希望对其执行过滤器。
I see that it's quite possible to do on a Linux machine, but I don't know how to go about filtering it on windows.我看到在 Linux 机器上很有可能做到,但我不知道如何在 Windows 上过滤它。
I would like every line that includes a specified string (eg cake
) to be copied into a new text file - simple as that.我希望包含指定字符串(例如
cake
)的每一行都被复制到一个新的文本文件中——就这么简单。 I just have no idea.我只是不知道。
Thanks :)谢谢 :)
You might want to use the MS-DOS find
command with redirection.您可能希望使用带有重定向的 MS-DOS
find
命令。 For example:例如:
find "cake" yourfile.txt > output.txt
You'll have to execute the line in the directory where your large text file is located.您必须在大文本文件所在的目录中执行该行。
Source: http://ss64.com/nt/find.html来源: http : //ss64.com/nt/find.html
C# with Visual Studio. C# 与 Visual Studio。
c# search string in txt file c#在txt文件中搜索字符串
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.