title: Count occurence of a string in a list and display it in console
body: <p>I'm creating a Logparser right now i'm able to go trought all the file in a folder line by line and extracting the substring i wanted which is the value after <code>"fct="</code>. All that using <code>Regex</code> and i put the result in a <code>List</code>.
  Now i want to <code>Count</code> the occurence of every string in my list and display it.</p>
  
  <p>I'm using GroupBy but when i display the result all the occurence are at <code>1</code>.</p>
  
  <p><strong>Actual:</strong></p>
  
  <pre><code> 720 1x
   720 1x
   710 1x
  </code></pre>
  
  <p>And it should be:</p>
  
  <pre><code> 720 2x
   710 1x  
  </code></pre>
  
  <p>I was able to find that the problem is that i read my file line by line so if the <code>"fct="</code> value is not twice on the same line it won't count it a <code>2</code> but only at <code>1</code> for every line that its appears.</p>
  
  <p>So i need to find a way to count my list and not my file line by line.</p>
  
  <p>I'm really beginner so not sure how to do this any tips would be appreciated.</p>
  
  <p>Here's the log data example:</p>
  
  <pre><code>&lt;dat&gt;FCT=10019,XN=KEY,CN=ROHWEPJQSKAUMDUC&lt;/dat&gt;&lt;/logurl&gt;
  &lt;dat&gt;XN=KEY,CN=RTU FCT=4515&lt;/dat&gt;LBZ=test.sqi&lt;/logurl&gt;
  &lt;dat&gt;XN=KEY,CN=RT&lt;/dat&gt;FCT=10019&lt;/logurl&gt;
  </code></pre>
  
  <p>I want to display:</p>
  
  <pre><code> FCT=10019 2x
   FCT=4515 1x
  </code></pre>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>   class Program
  {
  
      static void Main(string[] args)
      {
  
          int counter = 0;
          string[] dirs = Directory.GetFiles(@"C:/LogParser/LogParserV1", "*.txt");
          StreamWriter sw = new StreamWriter("C:/LogParser/LogParserV1/test.txt");      
          char[] delimiters = { '&lt;', ',', '&amp;', ':', ' ', '\\', '\'' };
          string patternfct = "(?&lt;=FCT=)[0-9]*";
  
  
          foreach (string fileName in dirs)
          {
              StreamReader sr = new StreamReader(fileName);
  
              {
                  String lineRead;
                  while ((lineRead = sr.ReadLine()) != null)
                  {
  
                      //To find all the value of fct= occurence 
                      var listfct = Regex.Matches(lineRead, patternfct, 
    RegexOptions.IgnoreCase).Cast&lt;Match&gt;().Select(x =&gt; x.Value).ToList();
  
  
                     var fctGroups = listfct.GroupBy(i =&gt; i);
                      foreach (var grp in fctGroups)
                      {
                          var fct = grp.Key;
                          var total = grp.Count();
                          System.Console.WriteLine("fct=" + fct + " " + "Total=" + total);
                      }
  
                      counter++;
                  }
                  System.Console.WriteLine(fileName);
  
                  sr.Close();
                  sw.Close();
              }
          }
  
          // Suspend the screen.  
          System.Console.ReadLine();
  
      }
  }
  }
  </code></pre>