Built-in awk for .NET?

Is there an AWK implementation for .NET?

To be more specific, here is an example of the problems I want to solve:

Article number Price Package day 10.1002-50 $50 Tuesday 10.1002-51 $40 Monday 10.1002-52 $50 10.1002-53 $50 Tuesday #start prepackaged 20.2001-51 $1 Monday 20.2001-52 $30 Tuesday 10.1002-54 $10 Tuesday 10.1002-55 #end prepackaged 10.1001-50 10.1002-50 $50 Friday 10.1003-50 10.1004-50 

I want to get article numbers, but skip pre-packaged ones.

Here's how I can imagine that you can solve it using the AWK implementation available in C #:

 using Awk.Extensions; string[][] output = System.IO.File.ReadLines("C:\Temp\input.txt") .Skip(1) .Awk("/start prepackaged/,/end prepackaged/ {next}; {print $1}") .Select(fields => fields[0]) .Distinct() .ToArray(); foreach(var item in output) { Console.WriteLine(item); } 

Then it would ideally provide an exit:

 10.1002-50 10.1002-51 10.1002-52 10.1002-53 10.1001-50 10.1003-50 10.1004-50 

Is there something similar? Are there some more powerful, line-based scripting libraries for .NET? Should I consider?

Further research shows that Jawk, a Java awk implementation that can also compile AWK scripts for Java bytecode! There seems to be a direct port to this in C # , although it doesn't seem very mature.

Another project for Java, awk4j :

 private static void case03() throws ScriptException { ScriptEngine engine = new ScriptEngineManager().getEngineByName("awk4j"); CompiledScript obj = ((Compilable) engine).compile("BEGIN{ printf ARGV[1] }"); // コンパイルengine.put(ScriptEngine.ARGV, new String[] { "hello," }); obj.eval(); // コンパイル済みのスクリプトを実行engine.put(ScriptEngine.ARGV, new String[] { "world!\n" }); obj.eval(); } 

Here's a similar question: Is there a .NET library that will give me the ability to run awk scripts in a .NET environment?

+7
c # scripting awk embed
source share
1 answer

There is an AWK for .NET . AWK is excellent, and I use it on Linux.

+2
source share

All Articles