Source Code : Mimic the Unix Grep command
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Mimic the Unix Grep command
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
public class GrepReader extends BufferedReader {
String pattern;
public GrepReader(Reader in, String pattern) {
super(in);
this.pattern = pattern;
}
public final String readLine() throws IOException {
String line;
do {
line = super.readLine();
} while ((line != null) && line.indexOf(pattern) == -1);
return line;
}
public static void main(String args[]) {
try {
GrepReader in = new GrepReader(new FileReader("GrepReader.java"), "GrepReader");
String line;
while ((line = in.readLine()) != null)
System.out.println(line);
in.close();
} catch (Exception e) {
System.err.println(e);
}
}
}
Thank with us