Quick-and-dirty regular expressions with Runter

Published: Mon 17 July 2017
By EWS

In Blog.

Parts 1 and 2 of a series about Regex discoverability in .NET led me to write a very small utility for "quick-and-dirty" regular expression matching (that is, of the same level of quick-and-dirtiness as sed or awk).

Introducing Runter:

// Find the line number of the last line in a file containing a string
//
File.WriteAllLines("/tmp/temp.txt",
    new[] {
    "Alea jacta est",
    "Veni vidi",
    "Carpe diem",
    "Carpe noctem" });
new FileInfo("/tmp/temp.txt").Runt("diem").Max(t => t.LineNumber);
3
// Extract IP addresses from iptables logs where there were ssh attempts
// (IP's obfuscated to protect the innocent):

new FileInfo("/tmp/logs").Runt(@"SRC=(\S+).*DPT=22").
    SelectMany(t => t.Matches).Distinct()
{ "101.174.104.95", "176.53.31.151", "117.65.43.100", "91.197.131.103",
"74.130.145.101", "111.14.7.144", "115.141.119.115" }

Comments !

social