[英]How to create grep command in java as linux grep command
I want a simple Java application which will work like linux grep
command, also take input from pipeline.我想要一个简单的 Java 应用程序,它可以像 linux grep
命令一样工作,也可以从管道中获取输入。
Thanks谢谢
1st U have to check for command line args
1st 你必须检查命令行args
if avail more than 2 arguments
then, 1st one is radix and 2nd one is file name read file line by line, match the radix string, and print it如果使用超过2 arguments
则第一个是基数,第二个是文件名逐行读取文件,匹配基数字符串,然后打印
if command line is only 1 argument
then you should check for System.in
which comes from pipeline read line by line and check that single arg String as radix and print it.如果命令行只有1 argument
那么您应该检查System.in
,它来自管道逐行读取,并检查该单个 arg String 作为基数并打印它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.