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 :)

Cherona
  • 758
  • 2
  • 10
  • 27
  • If you are comfortable with nix environments, try 'cygwin'... – MJSG Dec 23 '14 at 17:25
  • Possible duplicate of [Filter a text file into a new text file](http://stackoverflow.com/questions/8297706/filter-a-text-file-into-a-new-text-file) – Wolf Jan 25 '17 at 10:40
  • This size `3MB over 50,000` may be considered "large" for interactive filtering, but it's indeed small for filtering in an automated way. See [Large file support - Wikipedia](https://en.wikipedia.org/wiki/Large_file_support) – Wolf Jan 25 '17 at 10:48

2 Answers2

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

Yellows
  • 693
  • 4
  • 14
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();
Community
  • 1
  • 1
GlobalJim
  • 1,149
  • 2
  • 16
  • 24