0

I have a large text file (3MB over 50,000 lines) and I would wish to perform a filter on it.

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.

I would like every line that includes a specified string (e.g. cake) to be copied into a new text file - simple as that. I just have no idea.

Thanks :)

3

2 Answers 2

5

You might want to use the MS-DOS find command with redirection. 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

0
0

C# with Visual Studio.

c# search string in txt file

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();

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.