Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:03+00:00 2026-05-28T02:45:03+00:00

I have a two huge text files whose format is as below. File 1:

  • 0

I have a two huge text files whose format is as below.

File 1:

ID1,20
ID2,20
ID3,30

File 2:

ID3,75
ID1,84
ID2,70

Both these files contain more than 200,000 rows. I need to read both the files and create a third file in this format:

File 3:

ID1,20,84
ID2,20,70
ID3,30,75

ID can be any string that user inputs. Third file should be created by matching the ID in rows of file 1 to the id in rows of file 2. I have written a code but it takes a lot of time to generate File 3. The task at hand deals with parallelization, so I want the code to save me as much time as possible. Please suggest a faster and more efficient way to deal with this problem.

(Here is the code that I used)

public void positionCure(string afile,string bfile,string dfile)
    {
        string alphaFilePath = afile;

        List<string> alphaFileContent = new List<string>();

        using (FileStream fs = new FileStream(alphaFilePath, FileMode.Open))
        using(StreamReader rdr = new StreamReader(fs))
        {
            while(!rdr.EndOfStream)
            {
                alphaFileContent.Add(rdr.ReadLine());
            }
        }

        string betaFilePath = bfile;

        StringBuilder sb = new StringBuilder();


        using (FileStream fs = new FileStream(betaFilePath, FileMode.Open))
        using (StreamReader rdr = new StreamReader(fs))
        {

            while(! rdr.EndOfStream)
            {
                string[] betaFileLine = rdr.ReadLine().Split(Convert.ToChar(","));

                foreach (string alphaline in alphaFileContent)
                {
                        string[] alphaFileLine = alphaline.Split(Convert.ToChar(","));

                        if (alphaFileLine[0].Equals(betaFileLine[0].ToString()))
                        {
                            sb.AppendLine(String.Format("{0}, {1}, {2}", betaFileLine[0], betaFileLine[1], alphaline.Substring(alphaline.IndexOf(Convert.ToChar(","))+1)));
                        }

                }
            }


           }

        using (FileStream fs = new FileStream(dfile, FileMode.Create))
        using (StreamWriter writer = new StreamWriter(fs))
        {
            writer.Write(sb.ToString());
        }


        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:45:03+00:00Added an answer on May 28, 2026 at 2:45 am

    I would do something like:

    string[] files = new string[] { @"c:\temp\file1.txt", @"c:\temp\file2.txt" };
    var hash = new Dictionary<string, Dictionary<string, bool>>();
    foreach (var file in files)
    {
        string[] fileContents = File.ReadAllLines(file);
        foreach (string line in fileContents)
        {
            string[] a = line.Split(',');
            if (!hash.Keys.Contains(a[0]))
                hash[a[0]] = new Dictionary<string, bool>();
            hash[a[0]][a[1]] = true;
        }
    }
    foreach (var key in hash.Keys)
        Console.WriteLine(key + "," + string.Join(",", hash[key].Keys.ToArray()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that you have two huge files (several GB) that you want to concatenate
I have a huge XML file (114 KB/1719 lines; see the error message below
I have a huge text file (~1GB) and sadly the text editor I use
I have a huge line-separated text file and I want to make some calculations
I have two processes one will query other for data.There will be huge amount
Have two folders with approx. 150 java property files. In a shell script, how
I have two huge (as in millions of entries) sets (HashSet) that have some
I have a program that streams media, which creates two huge MemoryStreams, and then
I have two files, say source and target. I compare each element in source
Two problems, both caused by IE7 www.myvintagesecret.com 1) I have a Div called .postheader

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.