@@ -0,0 +1,2355 @@
+package io.dindinw.cmdline.tool;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader;%0Aimport java.io.PrintWriter;%0Aimport java.io.Reader;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.CharBuffer;%0Aimport java.nio.channels.FileChannel;%0Aimport java.nio.charset.Charset;%0Aimport java.util.Scanner;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport io.dindinw.cmdline.CmdLine;%0Aimport io.dindinw.cmdline.Option;%0Aimport io.dindinw.cmdline.Parser;%0A%0A/**%0A * A Java-version of unix tool 'grep'%0A * Created by alex on 3/13/15.%0A */%0Apublic final class JGrep %7B%0A    public static boolean show_line_number = false;%0A    public static void main(String%5B%5D args) throws Exception%7B%0A        Parser parser = new Parser();%0A        parser.addOption(new Option(%22-n%22,%22--line-number%22,%22print the matched line number%22));%0A        CmdLine cmd = parser.parse(args);%0A%0A        if (cmd.getArgs().length %3C 1) %7B%0A            System.err.println(%22Usage: JGrep pattern %5Bfile%5D%7CSystem.in %22); System.exit(1);%0A            System.exit(1);%0A        %7D%0A        Pattern p= Pattern.compile(cmd.getArgs()%5B0%5D);%0A        if (cmd.hasOption(%22-n%22))%7B%0A            //System.out.printf(%22show line number %5Cn%22);%0A           show_line_number = true;%0A        %7D%0A        if (cmd.getArgs().length == 1) %7B%0A            process(p,System.in);%0A        %7Delse%7B%0A            for (int i=1; i%3Ccmd.getArgs().length; i++)%0A                process(p, cmd.getArgs()%5Bi%5D);%0A        %7D%0A%0A    %7D%0A    static void process(Pattern pattern, InputStream input) throws IOException%7B%0A        BufferedReader br = new BufferedReader(new InputStreamReader(input));%0A%0A        Matcher m = pattern.matcher(%22%22);%0A        String line = null;%0A        int lineNum = 0;%0A        while ((line = br.readLine()) !=null)%7B%0A            lineNum++;%0A            m.reset(line);%0A            if (m.find())%7B%0A                String line_number = %22%22;%0A                if (show_line_number)%7B%0A                    line_number = %22%22+lineNum+%22:%22;%0A                %7D%0A                System.out.printf(%22%25s%25s%5Cn%22,line_number,line);%0A            %7D%0A        %7D%0A    %7D%0A%0A    static void process(Pattern pattern, String fileName) throws IOException %7B%0A        // Get a FileChannel from the given file.%0A        process(pattern, new FileInputStream(fileName)); // Map the file's content%0A%0A    %7D%0A%7D%0A

add JGrep. java version of unix grep. not-completed yet.