SHOW:
|
|
- or go back to the newest paste.
| 1 | - | static void Main(string[] args) |
| 1 | + | using System; |
| 2 | using System.Collections.Generic; | |
| 3 | using System.IO; | |
| 4 | using System.Linq; | |
| 5 | using System.Text; | |
| 6 | using System.Threading.Tasks; | |
| 7 | ||
| 8 | namespace TextFilter | |
| 9 | {
| |
| 10 | class Program | |
| 11 | {
| |
| 12 | static void Main(string[] args) | |
| 13 | {
| |
| 14 | if (args.Length < 3) | |
| 15 | {
| |
| 16 | Console.WriteLine("Format:\r\nTextFilter.exe input.txt output.txt findWord1,findWord2");
| |
| 17 | return; | |
| 18 | } | |
| 19 | ||
| 20 | string infile = args[0]; | |
| 21 | string outfile = args[1]; | |
| 22 | string[] find = args[2].Split(',');
| |
| 23 | bool findOne = find.Length == 1; | |
| 24 | Console.WriteLine("In: " + infile);
| |
| 25 | Console.WriteLine("Out: " + outfile);
| |
| 26 | Console.WriteLine("Find: " + String.Join(",", find));
| |
| 27 | ||
| 28 | if (!File.Exists(infile)) | |
| 29 | {
| |
| 30 | Console.WriteLine("Input file " + infile + " not exist!");
| |
| 31 | return; | |
| 32 | } | |
| 33 | ||
| 34 | DateTime startTime = DateTime.Now; | |
| 35 | Console.WriteLine("Start time : " + startTime);
| |
| 36 | int counter = 0; | |
| 37 | ||
| 38 | using (StreamWriter sw = new StreamWriter(outfile)) | |
| 39 | {
| |
| 40 | using (StreamReader sr = new StreamReader(infile)) | |
| 41 | {
| |
| 42 | String line; | |
| 43 | while ((line = sr.ReadLine()) != null) | |
| 44 | {
| |
| 45 | if ((findOne && line.Contains(find[0])) || find.Any(x => line.Contains(x))) | |
| 46 | {
| |
| 47 | if (++counter % 100 == 0) | |
| 48 | {
| |
| 49 | - | } |
| 49 | + | |
| 50 | Console.WriteLine(counter + " : " + line); | |
| 51 | } | |
| 52 | sw.WriteLine(line); | |
| 53 | } | |
| 54 | } | |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | Console.WriteLine("Done. Filtering time : " + (DateTime.Now - startTime));
| |
| 59 | Console.ReadLine(); | |
| 60 | } | |
| 61 | } | |
| 62 | } |