Hi, I have two text files. Textfile1 has data line by line (50000 lines) and in each line, there are 500 numeric values. Textfile2 has only one column (only numeric data) which matches the first column of Textfile1. Textfile2 may have 5000 lines (Each line has one numeric value).
Now my task is to read Textfile2 line by line, read its numeric value and match with the first numeric value of Textfile1, If it matches, then it should copy the whole line and paste it to Textfile3. Please help me to do this. I am new to C#, so just tried in the following program.

static void Main(string[] args)
        {
            StringBuilder strFile = new StringBuilder();

            using (StreamReader reader = new StreamReader(@"F:\Experiment 2\CM\CM Model Files\cm.txt"))
            {
                using (StreamWriter outfile = new StreamWriter(@"F:\Experiment 2\CM\CM Model Files\cm.test"))
                    for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
                    {

                        char[] charsToTrim = { ' ', '\r', '\n' };
                        string kkj = (line.TrimEnd(charsToTrim));

                        string[] words = kkj.Split(' ');
                        if (words[0] == "3010")
                            line.CopyTo();

                        strFile.AppendLine();
                        outfile.Write(strFile.ToString());
                        strFile.Clear();
                    }
            }
        }
This article has been dead for over six months. Start a new discussion instead.