// This example is from the book _Java in a Nutshell_ by David Flanagan. // Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. // You may study, use, modify, and distribute this example for any purpose. // This example is provided WITHOUT WARRANTY either expressed or implied. import java.io.*; import Util.*; // This class demonstrates the use of the GrepInputReader class. // It prints the lines of a file that contain a specified substring. public class Grep { public static void main(String args[]) { if ((args.length == 0) || (args.length > 2)) { System.out.println("\nUsage: java Grep "); new Pausa(); System.exit(0); } try { BufferedReader d; if (args.length == 2) d = new BufferedReader(new FileReader(args[1])); else d = new BufferedReader(new InputStreamReader(System.in)); GrepReader g = new GrepReader(d, args[0]); System.out.println("\nResult of java Grep " + args[0] + " " + args[1] + "\n"); String line; for(int i=1;;++i) { line = g.readLine(); if (line == null) break; System.out.println(" " + i + " : " + line.trim()); } g.close(); } catch (IOException e) { System.err.println(e); } new Pausa(); } }