Question: How to implement a file processing command line utility in Java, where the tool is titled fileUtil Syntax - input to command line should be:

How to implement a file processing command line utility in Java, where the tool is titled "fileUtil"

Syntax - input to command line should be:

fileUtil OPTIONS FILE

Where fileUtil is the program name, options are specified transformations, and a file is a .txt file which can be empty or containing a string, ex: "myexamplestring1"

Description

Program should perform basic text transformations on lines of text from an input FILE. Unless the -f option (see below) is specified, the program writes transformed text to a standrd output file (outfile) and errors/usage messages to a standard error file (errfile). The FILE parameter is required and must be the last parameter. OPTIONS may be zero or more of the following and may occur in any order:

  • -f
  • Edit file in place. The program overwrites the input file with transformed text instead of writing to stdout.
  • -d
  • Duplicate line numbers to each line, from 1-10.
  • -c
  • enable a cipher from -25 to 25, shifting each letter from a-z or z-a.
  • -r
  • Replaces the first instance of string1 in each line with string2.
  • -i
  • Used with the -r flag ONLY; Applies case insensitive matching -r.
  • -o
  • Writes the transformed file to a specified output file
  • -p <string>
  • Adds string as a prefix to each line.

NOTES:

  • While the last command-line parameter provided is always treated as the filename, OPTIONS flags can be provided in any order and will be applied as follows:
  • Options -f, -i, and -g should be processed first, as they determine global parameters of the computation.
  • Options -s, -r, -p, and -n should be processed in this order. That is: (1) file content is first filtered based on the parameter of option -s, if present; (2) replacements are performed based on the parameters of option -r, if present; (3) A prefix will be added after filtering and replacements are done; (4) Line numbering will be applied last.
  • Specifying option -i without having specified option -r should result in an error.
  • Specifying option -r with specified option -c should result in an error.
  • If options are repeated, only their last occurrence is considered.
  • Specifying option -r with an empty string1 parameter should result in an error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!