Need to do make utility to find lines in a txt that contain certain words in Java
I have an assignment like follows..can some one help me do this..?
You are required to write a programme that will find lines in a text file that contain certain words. This is broadly similar to the Unix utility "grep" in concept but a number of extra facilities are required.
The command line arguments are to be
1. -a or -o
A single flag of the form "-o" or "-a" specifying whether a required line will be one containing any one of the specified words ("-o" [OR] operation) or whether a required line is one containing all of the specified words ("-a" [AND] operation).
The default is "-o" operation.
2. -w, -t or -r
A single flag of the form "-w", "-t" or "-r" specifying the type of word match. These are
word matching means that the word specified on the command line must be matched exactly by a word in the line of text. This is indicated by the "-w" flag.
stem matching means that the word specified on the command line may be an initial substring of a word in the line of text. This is indicated by the "-t" flag.
string matching means that the word specified on the command line is to be taken as a string of characters that occur anywhere in the line of text. This is indicated by the "-r" flag.
For example if the word "man" appeared on the command line and stem matching were specified then words such as "mankind" and "manufacturing" would be regarded as matching, if string matching were specified then words such as "command" and "woman" would also match.
Stem matching is the default option.
The matching is required to be case insensitive. A word is to be taken as any sequence of alphameric characters enclosed by non-alphameric characters.
3. File name
The command line argument following "-f" is to be taken as the name of the file to be processed.
This is optional. If the "-f" option does not appear on the command line then data is read from standard input.
4. The words
A list of one (or more) words to be found in the data file. This is not optional, the absence of any required words is an error.
The output from the programme will be those lines of text read from the input data that satisfy the match requirements. The selected lines will be written to the standard output. You will be expected to devise a realistic set of tests for your programme and show its correct operation on a variety of data files.
Your programme should be written in standard Java.
Any help is appreciated
Looks to me that you will be exercising the Scanner class and the String class and the Regex and Pattern classes. Be sure you are methodical in your plan - you'll have two different input streams; you'll have to look for whole strings or substrings at the start of a word or content within a word.
Is your output list a list of words or lines?
By Ant_Magma in forum Java
Last Post: 09-20-2005, 11:49 PM
By Mike Tsakiris in forum .NET
Last Post: 10-04-2002, 05:32 PM
By Kelvin in forum Careers
Last Post: 09-24-2002, 09:42 AM
By Dharmesh in forum .NET
Last Post: 10-01-2001, 03:47 PM
By JayinMichigan in forum Careers
Last Post: 06-20-2001, 02:46 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL