Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- if (args.Length < 3)
- {
- Console.WriteLine("Format:\r\nTextFilter.exe input.txt output.txt findWord1,findWord2");
- return;
- }
- string infile = args[0];
- string outfile = args[1];
- string[] find = args[2].Split(',');
- bool findOne = find.Length == 1;
- Console.WriteLine("In: " + infile);
- Console.WriteLine("Out: " + outfile);
- Console.WriteLine("Find: " + String.Join(",", find));
- if (!File.Exists(infile))
- {
- Console.WriteLine("Input file " + infile + " not exist!");
- return;
- }
- DateTime startTime = DateTime.Now;
- Console.WriteLine("Start time : " + startTime);
- int counter = 0;
- using (StreamWriter sw = new StreamWriter(outfile))
- {
- using (StreamReader sr = new StreamReader(infile))
- {
- String line;
- while ((line = sr.ReadLine()) != null)
- {
- if ((findOne && line.Contains(find[0])) || find.Any(x => line.Contains(x)))
- {
- if (++counter % 100 == 0)
- {
- sw.Flush();
- Console.WriteLine(counter + " : " + line);
- }
- sw.WriteLine(line);
- }
- }
- }
- }
- Console.WriteLine("Done. Filtering time : " + (DateTime.Now - startTime));
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment