Note that there are some explanatory texts on larger screens.

plurals
  1. PORead in a file using a regular expression?
    primarykey
    data
    text
    <p>This is tangentially related to <a href="https://stackoverflow.com/questions/12939597/returning-the-regular-expression-match-as-part-of-a-split-or-equivalent-functio">an earlier question of mine.</a></p> <p>Essentially, the solution in that question worked great, but now I need to adapt it to work in a much larger analysis application. Simply using <code>StreamReader.ReadToEnd()</code> is not acceptable, since some of the files I will be reading in are very, very large. If there's been a mistake and someone forgot to clean up, they can theoretically be gigabytes big. Obviously I can't just read to the end of that.</p> <p>Unfortunately, the normal read lines is also not acceptable, because some of the rows of data I am reading in contain stack traces - they obviously use <code>/r/n</code> in their formatting. Ideally, I would like to tell the program to read forward until it hits a match for a regex, which it then returns. Is there any functionality to do this in .net? If not, can I get some suggestions for how I'd go about writing it?</p> <p>Edit: To make it a bit easier to follow my question, here's a paste of some of the important parts of the adapted code:</p> <pre><code>foreach (var fileString in logpath.Select(log =&gt; new StreamReader(log)).Select(fileStream =&gt; fileStream.ReadToEnd())) { const string junkPattern = @"\[(?&lt;junk&gt;[0-9]*)\] \((?&lt;userid&gt;.{0,32})\)"; const string severityPattern = @"INFO|ERROR|FATAL"; const string datePattern = "^(?=[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3})"; var records = Regex.Split(fileString, datePattern, RegexOptions.Multiline); foreach (var record in records.Where(x =&gt; string.IsNullOrEmpty(x) == false)) ...... </code></pre> <p>The problem lies in the Foreach. <code>.Select(fileStream =&gt; fileStream.ReadToEnd())</code> is gonna blow up memory badly, I just know it.</p>
    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.
 

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