COP 4225 Advanced Unix Programming
Project 2

 

Description 

     We define the statistics of a word to be x1.x2.x3.x4, where x1 is the total number of uppercase letters in the word; x2 is the total number of lowercase letters in the wordx3 is the total number of digits in the word;  x4 is the total number of the other characters in the word. Therefore,  the statistics of the word "COP-4225:" is 3.0.4.2.     

      In this project, you are required to write a Korn shell script (please do not use AWK or Sed) to replace the ith to the jth words of each line in a file to their corresponding statistics. All the other words and newlines are untouched. The format of the command is as follows:

      getstat -s i -e j   [filename ]    

      The modified content will be echoed to the standard output. If filename is not provided, getstat echoes each line of the standard input (the keyboard) and then echoes the modified line, until Ctrl-D is encountered. If  "-s i" is missing, i is set to be 1. If "-e j" is missing, j points to the last word in a line. Although words in the input can be separated by multiple whitespaces (space or tab), words are separated by single spaces (" ") in the output of getstat.

     As an exampe, if the file mydata contains just one line: "Class COP4225:     Advanced Unix Programming", then " getstat  -s 2 mydata" should return "Class 3.0.4.1 1.7.0.0 1.3.0.0 1.10.0.0".

Hint

      The command "cut" (p. 179 of the textbook) may help.

Submission

Grading

test script   test input