title: Replace Long list Words in a big Text File
body: <p>i need a fast method to work with big text file</p>
  
  <p>i have 2 files,
  a big text file (~20Gb) 
  and an another text file that contain ~12 million list of Combo words </p>
  
  <p>i want find all combo words in the first text file and replace it with an another Combo word (combo word with underline)</p>
  
  <p>example "Computer Information"  >Replace With>  "Computer_Information"</p>
  
  <p>i use this code, but performance is very poor (i test in Hp G7 Server With 16Gb Ram and 16 Core)</p>
  
  <pre><code>public partial class Form1 : Form
  {
      HashSet&lt;string&gt; wordlist = new HashSet&lt;string&gt;();
  
      private void loadComboWords()
      {
          using (StreamReader ff = new StreamReader(txtComboWords.Text))
          {
              string line;
              while ((line = ff.ReadLine()) != null)
              {
                  wordlist.Add(line);
              }
          }
      }
  
      private void replacewords(ref string str)
      {
  
          foreach (string wd in wordlist)
          {
            //  ReplaceEx(ref str,wd,wd.Replace(" ","_"));
              if (str.IndexOf(wd) &gt; -1)
                  str.Replace(wd, wd.Replace(" ", "_"));
          }
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          string line;
          using (StreamReader fread = new StreamReader(txtFirstFile.Text))
          {
              string writefile = Path.GetFullPath(txtFirstFile.Text) + Path.GetFileNameWithoutExtension(txtFirstFile.Text) + "_ReplaceComboWords.txt";
              StreamWriter sw = new StreamWriter(writefile);
              long intPercent;
              label3.Text = "initialing";
              loadComboWords();
  
              while ((line = fread.ReadLine()) != null)
              {
                  replacewords(ref line);
                  sw.WriteLine(line);
  
                  intPercent = (fread.BaseStream.Position * 100) / fread.BaseStream.Length;
                  Application.DoEvents();
                  label3.Text = intPercent.ToString();
              }
              sw.Close();
              fread.Close();
              label3.Text = "Finished";
          }
      }
  }
  </code></pre>
  
  <p>any idea to do this job in reasonable time </p>
  
  <p>Thanks</p>