Example #1
0
        public static int main()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read(@"c:/dev/asclepius/prod_import/events.csv");
                p.grep("CL/C/MonitoringDashboard/");
                p.sed("MonitoringDashboard[/][^.]+[.]", "MonitoringDashboard.");
                p.sed("CL/C/MonitoringDashboard.", "");
                p.parseCsv();
                p.withColumns(p2 => { p2.sed(",", "", "g"); }, 2, 3);
                p.lineTransformerFunc(line => TextUtil.encodeSqlValue(line));
                p.print("insert into `groupit` values($1,$2);");
                p.write(@"c:/dev/asclepius/prod_import/events.sql");
            }

            return(0);
        }
Example #2
0
 public void readImproperState()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString(EARTH);
         p.sed("Ter.*", "Forma", "g");
         Assert.Throws <IllegalStateException>(() => p.readString(EARTH));
     }
 }
Example #3
0
 // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleProcessorChain sedShim
 public static void sedShim()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("CSV,INPUT!,\"Go, Pnyx Go\"");
         p.parseCsv();
         p.sed("[,!]", "_", "g");
         p.writeStdout();
     }
     // outputs: CSV,INPUT_,"Go_ Pnyx Go"
 }
Example #4
0
 public static void helloWorld()
 {
     using (Pnyx p = new Pnyx())
     {
         p.readString("Hello World.");
         p.sed("World", "World, with love from Pnyx.."); // transforms each line
         p.grep("world", caseSensitive: false);          // filters each line
         p.writeStdout();
         p.compile();                                    // Builds processors and wires filters together
         p.process();                                    // Runs processors (All IO is done here)
     }
     // outputs: Hello World, with love from Pnyx...
 }
Example #5
0
        // pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleLine parseDelimiter
        public static void parseDelimiter()
        {
            const String input = "a|b|c|d|e|f|g";

            using (Pnyx p = new Pnyx())
            {
                p.readString(input);
                p.sed("[aceg]", @"\0\0", "gi");     // duplicates every other char
                p.parseDelimiter("|");
                p.print("$1,$3,$5,$7|$2,$4,$6");
                p.writeStdout();
            }
            // outputs: aa,cc,ee,gg|b,d,f
        }
Example #6
0
        public void lineTransform()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.sed(",", "\t", "g");
                actual = p.processToString();
            }

            const String expected = "Gaia\tTerra\t\"Mother goddess of the earth\"";

            Assert.Equal(expected, actual);
        }
Example #7
0
        public void rowTransform()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(EARTH);
                p.parseCsv();
                p.sed("Ter.*", "Forma", "g");
                actual = p.processToString();
            }

            const String expected = "Gaia,Forma,\"Mother goddess of the earth\"";

            Assert.Equal(expected, actual);
        }
Example #8
0
        public void tabHasHeader()
        {
            const String source = "headerA\theaderB\nvalueA1\tvalueB1";
            String       actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(source);
                p.parseTab(hasHeader: true);
                p.sed("[AB]", "X");
                actual = p.processToString();
            }

            const String expected = "headerA\theaderB\nvalueX1\tvalueX1";

            Assert.Equal(expected, actual);
        }
Example #9
0
        public void lineToRow()
        {
            String       actual;
            const String tabSource = "1) Be fruitful and multiply\t2) and fill the earth and subdue it";

            using (Pnyx p = new Pnyx())
            {
                p.readString(tabSource);
                p.sed("[\t]", ",", "g");
                p.parseCsv(strict: false);
                actual = p.processToString();
            }

            const String expected = @"""1) Be fruitful and multiply"",""2) and fill the earth and subdue it""";

            Assert.Equal(expected, actual);
        }
Example #10
0
        public void hasHeader()
        {
            const String source = @"headerA,headerB
valueA1,valueB1
";
            String       actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(source);
                p.parseCsv(hasHeader: true);
                p.sed("[AB]", "X");
                actual = p.processToString();
            }

            const String expected = @"headerA,headerB
valueX1,valueX1
";

            Assert.Equal(expected, actual);
        }