C# code to figure out missing lines between two text files

static void Main(string[] args)

        {

            try

            {

                int flag = 0;

                StreamReader srt = new StreamReader(@"C:\More.txt");

                for (string str = srt.ReadLine(); str != null; str = srt.ReadLine())

                {

                    flag = 0;

                    StreamReader srf = new StreamReader(@"C:\Less.txt");

                    for (string st = srf.ReadLine(); st != null; st = srf.ReadLine())

                    {

                        if (str == st)

                        {

                            flag = 1;

                            break;

                        }

                    }

                    if (flag == 0)

                    {

                        StreamWriter sw = new StreamWriter(@"C:\Diff.txt", true);

                        sw.WriteLine(str);

                        sw.Close();

                    }

                    srf.Close();

                }

                srt.Close();

 

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s