Unix Commands  «Prev  Next»

Search Player Script - Exercise


Objective: Write a script to search the volleylist file for players.

Exercise scoring


This exercise is worth 20 points .

Background/overview

In this exercise, you will begin to create the course project, the volleyball program. The main script, called volleyball, has been written for you. This script calls various other scripts, which you will write. In this exercise, you will write a script to search the volleylist file.
There is a subdirectory called course-project under your home directory. This directory contains a starting copy of the volleylist data file and the main volleyball script. You will use the volleylist file in this assignment. The volleyball script will call the script you are writing.

Instructions

Write the searchplayer script. This script should:
  1. Ask the user to enter a pattern to search for
  2. Search for matches on the pattern
  3. Sort the matches by last name
  4. Print the sorted matches on the screen
  5. If the user enters a pattern that does not match any lines, print a message asking them to try again with another pattern. Use grep –c for this.

Notes:
  1. The pattern does not need to be in a specific place on the line, a match anywhere will do.
  2. Use sleep to give the user time to see the output.
  3. This script should not loop. Looping is built into the volleyball program, so do not put a while loop into your program.

Sample run

Here is a sample of what your script might look like when it runs.
$ searchplayer
Please enter a pattern to search for: Anna

Here are your search results
---------------------------------------
Anna:Spike:Smith:12 Main St.:Palo Alto:CA:94303
---------------------------------------
$ searchplayer
Please enter a pattern to search for: junk
Your pattern does not match any players
---------------------------------------
Please try again
---------------------------------------

Submitting your exercise


Please paste your results into the field below and submit.