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();
                    }
            }
        }

No Help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.