Guest User

Untitled

a guest
Sep 18th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             if (args.Length < 3)
  4.             {
  5.                 Console.WriteLine("Format:\r\nTextFilter.exe input.txt output.txt findWord1,findWord2");
  6.                 return;
  7.             }
  8.  
  9.             string infile = args[0];
  10.             string outfile = args[1];
  11.             string[] find = args[2].Split(',');
  12.             bool findOne = find.Length == 1;
  13.             Console.WriteLine("In: " + infile);
  14.             Console.WriteLine("Out: " + outfile);
  15.             Console.WriteLine("Find: " + String.Join(",", find));
  16.  
  17.             if (!File.Exists(infile))
  18.             {
  19.                 Console.WriteLine("Input file " + infile + " not exist!");
  20.                 return;
  21.             }
  22.  
  23.             DateTime startTime = DateTime.Now;
  24.             Console.WriteLine("Start time : " + startTime);
  25.             int counter = 0;
  26.  
  27.             using (StreamWriter sw = new StreamWriter(outfile))
  28.             {
  29.                 using (StreamReader sr = new StreamReader(infile))
  30.                 {
  31.                     String line;
  32.                     while ((line = sr.ReadLine()) != null)
  33.                     {
  34.                         if ((findOne && line.Contains(find[0])) || find.Any(x => line.Contains(x)))
  35.                         {
  36.                             if (++counter % 100 == 0)
  37.                             {
  38.                                 sw.Flush();
  39.                                 Console.WriteLine(counter + " : " + line);
  40.                             }
  41.                             sw.WriteLine(line);
  42.                         }
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             Console.WriteLine("Done. Filtering time : " + (DateTime.Now - startTime));
  48.             Console.ReadLine();
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment