Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Created October 14, 2019 13:24
Show Gist options
  • Save nramsbottom/1ac94532a5c375c366e08558682b7b71 to your computer and use it in GitHub Desktop.
Save nramsbottom/1ac94532a5c375c366e08558682b7b71 to your computer and use it in GitHub Desktop.
LogFilter - Simple application for filtering content from large w3c logs.
using System.IO;
namespace LogFilter
{
class Program
{
static void Main(string[] args)
{
const string InputPath = @"D:\Temp\u_ex191014.log";
const string OutputPath = @"D:\Temp\output.log";
using var input = new StreamReader(InputPath);
using var output = new StreamWriter(OutputPath);
while (true)
{
var line = input.ReadLine();
if (string.IsNullOrEmpty(line))
break;
// comment
if (line.StartsWith("#"))
continue;
// date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
var tokens = line.Split(' ');
// ignore these originating addresses
if (tokens[8] == "172.18.25.1" || tokens[8] == "172.18.100.52")
continue;
// status code must be 500
if (tokens[11] != "500")
continue;
// path must start with /v2
if (!tokens[4].StartsWith("/v2"))
continue;
output.WriteLine(line);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment