Last active
August 29, 2015 14:10
-
-
Save staafl/685f8855a059e78b8044 to your computer and use it in GitHub Desktop.
extract-pattern-from-file.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
class Program | |
{ | |
static int Main(string[] args) | |
{ | |
foreach (string line in args[0] == "-" ? ReadConsole() : File.ReadLines(args[0])) | |
{ | |
Match mm = Regex.Match(line, args[1]); | |
if (mm.Success) | |
{ | |
Console.WriteLine( | |
mm.Groups.Count == 1 | |
? mm.Value | |
: string.Join("", mm.Groups.OfType<Group>().Skip(1).Select(g => g.Value))); | |
return 0; | |
} | |
} | |
return 1; | |
} | |
static IEnumerable<string> ReadConsole() | |
{ | |
while (true) | |
{ | |
string line = Console.ReadLine(); | |
if (line == null) | |
{ | |
yield break; | |
} | |
else | |
{ | |
yield return line; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for /F %x in ('extract-pattern-from-file.exe dot.core.nuspec "<version>([^<]+)"') do set VERSION=%x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment