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

  • Home
  • SEARCH
  • 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 6978163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:43:11+00:00 2026-05-27T17:43:11+00:00

I have millions of lines generated from data updated every second which look like

  • 0

I have millions of lines generated from data updated every second which look like this:

104500 4783
104501 8930
104502 21794
104503 21927
104505 5746
104506 9968
104509 5867
104510 46353
104511 7767
104512 4903

The column on the left represents time (hhmmss format), and the column on the right is data which is updated second-by-second. As you can see however, it isn’t actually second-by-second, and there are some missing times (10:45:04, 10:45:07, 10:45:08 are missing in this example). My goal is to add in the missing seconds, and to use the data from the previous second for that missing second, like this:

104500 4783
104501 8930
104502 21794
104503 21927
104504 21927 --
104505 5746
104506 9968
104507 9968 --
104508 9968 --
104509 5867
104510 46353
104511 7767
104512 4903

I don’t want the “–” in the result, I just put those there to mark the added lines. So far I’ve tried to accomplish this using StreamReader and StreamWriter, but it doesn’t seem like they’re going to get me what I want. I’m a newbie programmer and a newbie to C#, so if you could just point me in the right direction, that would be great. I’m really just wondering if this is even possible to do in C#…I’ve spent a lot of time on MSDN and here on SO looking for a solution to this, but so far haven’t found any.

Edit: The lines are in a text file, and I want to store the newly created data in a new text file.

  • 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-27T17:43:12+00:00Added an answer on May 27, 2026 at 5:43 pm

    ok, here is the whole shooting match, tested and working against your test data:

    public void InjectMissingData()
    {
        DataLine lastDataLine = null;
        using (var writer = new StreamWriter(File.Create("c:\\temp\\out.txt")))
        {
            using (var reader = new StreamReader("c:\\temp\\in.txt"))
            {
                while (!reader.EndOfStream)
                {
                    var dataLine = DataLine.Parse(reader.ReadLine());
    
                    while (lastDataLine != null && dataLine.Occurence - lastDataLine.Occurence > TimeSpan.FromSeconds(1))
                    {
                        lastDataLine = new DataLine(lastDataLine.Occurence + TimeSpan.FromSeconds(1), lastDataLine.Data);
                        writer.WriteLine(lastDataLine.Line);
                    }
    
                    writer.WriteLine(dataLine.Line);
    
                    lastDataLine = dataLine;
                }
            }
        }
    }
    
    public class DataLine
    {
        public static DataLine Parse(string line)
        {
            var timeString = string.Format("{0}:{1}:{2}", line.Substring(0, 2), line.Substring(2, 2),
                                           line.Substring(4, 2));
    
            return new DataLine(TimeSpan.Parse(timeString), long.Parse(line.Substring(7, line.Length - 7).Trim()));
        } 
    
        public DataLine(TimeSpan occurence, long data)
        {
            Occurence = occurence;
            Data = data;
        }
    
        public TimeSpan Occurence { get; private set; }
        public long Data { get; private set; }
    
        public string Line
        {
            get { return string.Format("{0}{1}{2} {3}", 
                Occurence.Hours.ToString().PadLeft(2, Char.Parse("0")), 
                Occurence.Minutes.ToString().PadLeft(2, Char.Parse("0")), 
                Occurence.Seconds.ToString().PadLeft(2, Char.Parse("0")),
                Data); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file containing some user data it looks like this: 10333,,an.10,Kenyata,,Aaron,,,,,,,,,,
I have a perl script that processes millions of lines of performance data, so
I have a Plain text file with possibly millions of lines which needs custom
I have a file with n lines. (n above 100 millions) I want to
I have 100 million lines of data, the data is a word no longer
I have a tab-separated data file with a little over 2 million lines and
I have a very large app, 1.5 million lines of C++, which is currently
Which search engine would you recommend for a Commerce website? We have millions of
I have a millions of pairs of string of same length which I want
I have 32 million lines in a file and almost every line contains the

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.