简体   繁体   English

如何在 Windows 上的大型文本文件中搜索和提取包含特定字符串的行?

[英]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.

相关问题 如何使用Windows批处理脚本搜索字符串并从文本文件中提取另一个字符串模式 - How to search a string and extract another string pattern from a text file using windows batch script 如何制作一个批处理文件,告诉我文本文件的哪些行不在另一个文件中? - How can I make a batch file that will tell me which lines of a text file are NOT in another file? 如何使用Windows bash在文件中的字符串匹配中提取文本中的记录 - how to extract a record in a text on string match in a file using windows bash 如何重命名包含特定文本字符串的文件? - How to rename files that contain specific text string? 如何删除文件名中包含特定字符串的文件夹和所有子文件夹中的文件? - How to delete files in folders and all subfolders which contain specific string in file name? 在 Perl 窗口中删除大量文本后如何添加新行? - How do I add new lines after deleting a large amount of text in Perl windows? 如何在现有文本文件中的特定位置插入新的文本字符串 - How can I insert a new string of text into a specific location in existing text file 批处理文件以从文本文件中读取行,其中可能包含其他文件的引用 - Batch file to read lines from text file which may contain reference of other file 如何在没有CopyFile或CopyFileEx的情况下在Windows上复制大文件? - How can I copy a large file on Windows without CopyFile or CopyFileEx? 如何删除Windows中另一个文本文件中存在的文本文件中的所有行? - How do I remove all the lines in a text file that are present in another text file in Windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM