Note that there are some explanatory texts on larger screens.

plurals
  1. POI am having difficulty in parsing logs for a particular field with values having spaces?
    primarykey
    data
    text
    <p>I want to calculate total "Elapsed Time" in "GSA Search", but i am facing discrepancy. In some cases format is "Elapsed Time: 97ms" and in some cases it is "Elapsed Time:97ms". How can i cover both scenarios ? </p> <p>Following is my logs file format:</p> <pre> WX Search = Server:nomos-scanner.corp.com User:vibsharm appGUID: wx Elapsed Time: 975ms SaveSearchID:361 WX Search = Server:nomos-scanner.corp.com User:vibsharm appGUID: wx Elapsed Time: 875ms SaveSearchID:361 GSA Search = Server:nomos-scanner.corp.com User:gulanand appGUID: wx Elapsed Time:890ms SaveSearchID:361 GSA Search = Server:nomos-scanner.corp.com User:vibsharm appGUID: wx Elapsed Time:887ms SaveSearchID:361 GSA Search = Server:nomos-scanner.corp.com User: gulanand appGUID: wx Elapsed Time: 875.5ms SaveSearchID:361 GSA Search = Server:nomos-scanner.corp.com User:vibsharm appGUID: wx Elapsed Time:877.6ms SaveSearchID:361 </pre> <p>My code :</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Linq.Expressions; namespace ConsoleApplication5 { class Program { public static void Main(string[] args) { string searchKeyword = "WX GSA Search"; string fileName = @"C:\Users\karan\Desktop\Sample log file.txt"; string[] textLines = File.ReadAllLines(fileName); List&lt;string&gt; results = new List&lt;string&gt;(); foreach (string line in textLines) { if (line.Contains(searchKeyword)) { results.Add(line); } } var elapsedTime = results.SelectMany(line =&gt; line.ToLower().Split(' ')) .Where(line =&gt; line.StartsWith("time")) .Select(timeLine =&gt; decimal.Parse(timeLine.Split(':')[1].Replace("ms", String.Empty))) .Average(time =&gt; time); Console.WriteLine(elapsedTime); // keep screen from going away // when run from VS.NET Console.ReadLine(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload