import java.util.*;
import java.io.*;
/**
 *@author     Jeff
 *@created    February 13, 2003
 *@version    02092003
 */
public class Grep {
	/**
	 *  This is a method to grep a file and return any matches for a given key. It
	 *  takes two arguments from the command line: the search key and the file in
	 *  which to search.
	 *
	 *@param  args             Description of the Parameter
	 *@exception  IOException  Description of the Exception
	 */
	public static void main(String args[]) throws IOException {
		BufferedReader output = new BufferedReader(new InputStreamReader(System.in));
		if (args.length != 2) {
			System.out.println("\tPlease enter a search key followed by a file name.");
		}
		boolean found = false;
		int lineNum = 1;
		String key = args[0];
		try {
			FileReader file = new FileReader(args[1]);
			BufferedReader br = new BufferedReader(file);
			String inLine = br.readLine();
			while (inLine != null) {
				StringTokenizer sToken = new StringTokenizer(inLine, " .,:;\"!?@#$%&*");
				while (sToken.hasMoreTokens()) {
					String test = sToken.nextToken();
					if (key.equalsIgnoreCase(test)) {
						found = true;
						System.out.println("\nThe search key \"" + args[0] + "\" was found at line " + lineNum + ":");
						System.out.println("\n" + inLine);
						break;
					}
				}

				inLine = br.readLine();
				lineNum++;

			}
			if (found == false) {
				System.out.println("\nThe search key was not found in the file you requested.");
			}
		} catch (IOException e) {
			System.out.println("\nThe file you requested is not in the current directory.");
		}
	}
}

