Skip to main content.

Assignment 1: Word Counter in Bash

Due: Before Friday's class.

Objectives

After completing this assignment, a student should be more comfortable with basic systems programming, specifically writing Bash scripts containing Unix commands to solve problems.

Set up

Some information about working on the Linux machines remotely, if you're interested.

On your CS dept Linux account, create a cs330 directory and within that directory, create a directory called assign1. All files for this assignment should be stored in the assign1 directory.

A Note on the Use of External Sources

Recall that there is a directory of bash examples in the course's handouts directory.

You can search the web for help solving parts of the assignment, but you should not search for large chunks of the assignment, e.g., something like "list all the words in the file and how many times they occur". You often get more complex solutions than are necessary for this assignment. You should be able to piece much of this together from the class discussion and given examples.

Word Counter Specification

Write a bash script called mywc.sh that takes one or more file names on the command line and prints out, clearly labeled:

  1. The name of the file
  2. The number of lines and words in the file (but NOT characters)
  3. A list of all the words in the file and how many times they occur. The words should all be lower cased for the best results. (We won't worry about punctuation.)

Hint: you you will probably need to use/learn about pipe, loops, variables, echo, wc, cat, tr, sort, and uniq.

If the user does not enter any parameters, the program can just exit without output.

Testing

You should create several test files as input into the program, starting with test0, test1, ..., to test your script.

(These are just input files, not something that can automatically check if your code is correct.)

Submission

Copy your assign1 directory into your turnin directory, i.e., /csdept/courses/cs330/turnin/yourusername

After copying, check that either:

Note that this does not mean that everyone will be able to read the files. Only you and I should be able to read the files because (1) you are the owner, so you have read permission and (b) the turnin directory is owned by the turnin group, and I am the only member of the turnin group.

Ask well before the deadline if you need help turning in your assignment!

Grading (50 pts)

You will be assessed on