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 9046751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:43:38+00:00 2026-06-16T11:43:38+00:00

I’m reading a log file which has following contents DateTime: 2012-12-09 17:00:18 Command: ALTER

  • 0

I’m reading a log file which has following contents

DateTime: 2012-12-09 17:00:18
Command: ALTER INDEX [XPKAttribute] ON [FMC360Train_MSCRM].[MetadataSchema].[Attribute] REORGANIZE WITH (LOB_COMPACTION = ON)
Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: No, FileStream: No, AllowPageLocks: Yes, PageCount: 1336, Fragmentation: 10.1796
Outcome: Succeeded
Duration: 00:00:01
DateTime: 2012-12-09 17:00:19

DateTime: 2012-12-09 17:00:19
Command: ALTER INDEX [XPKLocalizedLabel] ON [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel] REORGANIZE WITH (LOB_COMPACTION = ON)
Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: Yes, FileStream: No, AllowPageLocks: Yes, PageCount: 2522, Fragmentation: 18.5964
Outcome: Succeeded
Duration: 00:00:01
DateTime: 2012-12-09 17:00:20

Here the regex code I’m using

var data = new Regex(@"^DateTime:\ (?<StartTime>[^\r]+)\r\nCommand: ALTER INDEX\ (?<Command>[^\r]+)\r\nComment:\ (?<Comment>[^\r]+)\r\nOutcome:\ (?<Outcome>[^\r]+)\r\nDuration:\ (?<Duration>[^\r]+)\r\nDateTime:\ (?<EndTime>[^\r]+)", RegexOptions.Multiline)
                .Matches(File.ReadAllText(@"C:\Users\dalvi\Desktop\Index Logs\trial.txt")).Cast<Match>().Select(m => new
                {
                    StartTime = m.Groups["StartTime"].Value,
                    Command = m.Groups["Command"].Value,
                    Comment = m.Groups["Comment"].Value,
                    Outcome = m.Groups["Outcome"].Value,
                    Duration = m.Groups["Duration"].Value,
                    EndTime = m.Groups["EndTime"].Value
                });

But the output I’m getting whole text after Command: and Comment: but I want
text after ON means [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel] and then the next text REORGANIZE as different value, how can i modify the regex code to get output like

StartTime   DBTableName Type    Comment Outcome Duration    EndTime
2012-12-09 17:00:18 [FMC360Train_MSCRM].[MetadataSchema].[Attribute]    REORGANIZE  PageCount: 1336 Succeeded   00:00:01    2012-12-09 17:00:19

My program is working to get a long output but I want output in above format so i need help
only on regex.

  • 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-06-16T11:43:41+00:00Added an answer on June 16, 2026 at 11:43 am

    I don’t know the exact rules for parsing your Command line, but the following regular expression works with your two example inputs:

    var data = new Regex(@"^DateTime:\ (?<StartTime>[^\r]+)\r\nCommand: ALTER INDEX \[([^\]]+)\] ON (?<DBTableName>\[([^\]]+)\]\.\[([^\]]+)\]\.\[([^\]]+)\]) (?<Type>[^ ]+) ([^\r]+)\r\nComment:\ (?<Comment>.+Fragmentation: (?<Fragmentation>[\d\.]+)[^\r]+)\r\nOutcome:\ (?<Outcome>[^\r]+)\r\nDuration:\ (?<Duration>[^\r]+)\r\nDateTime:\ (?<EndTime>[^\r]+)", RegexOptions.Multiline)
        .Matches(File.ReadAllText(@"C:\Users\dalvi\Desktop\Index Logs\trial.txt")).Cast<Match>().Select(m => new
            {
                StartTime = m.Groups["StartTime"].Value,
                DBTableName = m.Groups["DBTableName"].Value,
                Type = m.Groups["Type"].Value,
                Comment = m.Groups["Comment"].Value,
                Fragmentation = m.Groups["Fragmentation"].Value,
                Outcome = m.Groups["Outcome"].Value,
                Duration = m.Groups["Duration"].Value,
                EndTime = m.Groups["EndTime"].Value
            });
    

    EDIT:

    Below is a full console application running on your test data:

    class Program
    {
        static void Main(string[] args)
        {
            string input =
                @"DateTime: 2012-12-09 17:00:18
    Command: ALTER INDEX [XPKAttribute] ON [FMC360Train_MSCRM].[MetadataSchema].[Attribute] REORGANIZE WITH (LOB_COMPACTION = ON)
    Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: No, FileStream: No, AllowPageLocks: Yes, PageCount: 1336, Fragmentation: 10.1796
    Outcome: Succeeded
    Duration: 00:00:01
    DateTime: 2012-12-09 17:00:19
    
    DateTime: 2012-12-09 17:00:19
    Command: ALTER INDEX [XPKLocalizedLabel] ON [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel] REORGANIZE WITH (LOB_COMPACTION = ON)
    Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: Yes, FileStream: No, AllowPageLocks: Yes, PageCount: 2522, Fragmentation: 18.5964
    Outcome: Succeeded
    Duration: 00:00:01
    DateTime: 2012-12-09 17:00:20";
    
            var data = new Regex(@"^DateTime:\ (?<StartTime>[^\r]+)\r\nCommand: ALTER INDEX \[([^\]]+)\] ON (?<DBTableName>\[([^\]]+)\]\.\[([^\]]+)\]\.\[([^\]]+)\]) (?<Type>[^ ]+) ([^\r]+)\r\nComment:\ (?<Comment>.+Fragmentation: (?<Fragmentation>[\d\.]+)[^\r]+)\r\nOutcome:\ (?<Outcome>[^\r]+)\r\nDuration:\ (?<Duration>[^\r]+)\r\nDateTime:\ (?<EndTime>[^\r]+)", RegexOptions.Multiline)
                .Matches(input).Cast<Match>().Select(m => new
                {
                    StartTime = m.Groups["StartTime"].Value,
                    DBTableName = m.Groups["DBTableName"].Value,
                    Type = m.Groups["Type"].Value,
                    Comment = m.Groups["Comment"].Value,
                    Fragmentation = m.Groups["Fragmentation"].Value,
                    Outcome = m.Groups["Outcome"].Value,
                    Duration = m.Groups["Duration"].Value,
                    EndTime = m.Groups["EndTime"].Value
                });
    
            foreach (var datum in data)
            {
                Console.WriteLine("StartTime: {0}", datum.StartTime);
                Console.WriteLine("DBTableName: {0}", datum.DBTableName);
                Console.WriteLine("Type: {0}", datum.Type);
                Console.WriteLine("Comment: {0}", datum.Comment);
                Console.WriteLine("Fragmentation: {0}", datum.Fragmentation);
                Console.WriteLine("Outcome: {0}", datum.Outcome);
                Console.WriteLine("Duration: {0}", datum.Duration);
                Console.WriteLine("EndTime: {0}", datum.EndTime);
                Console.WriteLine();
            }
    
            Console.ReadKey();
        }
    }
    

    And this is its ouput:

    StartTime: 2012-12-09 17:00:18
    DBTableName: [FMC360Train_MSCRM].[MetadataSchema].[Attribute]
    Type: REORGANIZE
    Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: No, FileStream: No, AllowPageLocks: Yes, PageCount: 1336, Fragmentation: 10.1796
    Fragmentation: 10.179
    Outcome: Succeeded
    Duration: 00:00:01
    EndTime: 2012-12-09 17:00:19
    
    StartTime: 2012-12-09 17:00:19
    DBTableName: [FMC360Train_MSCRM].[MetadataSchema].[LocalizedLabel]
    Type: REORGANIZE
    Comment: ObjectType: Table, IndexType: Clustered, ImageText: No, NewLOB: Yes, FileStream: No, AllowPageLocks: Yes, PageCount: 2522, Fragmentation: 18.5964
    Fragmentation: 18.596
    Outcome: Succeeded
    Duration: 00:00:01
    EndTime: 2012-12-09 17:00:20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.