Scripts and Utilities -- Sed/Ed lab


  • Jim Plank
  • Due: 3:30 PM, Tuesday, July 1.
  • This file: http://www.cs.utk.edu/~plank/plank/classes/cs494/494/labs/Sed/lab.html
  • sed lecture notes
  • Guest TA: John Randle (randle@cs.utk.edu).
    Write the following shell scripts. When you're done, bundle them all up with shar and mail them to the Guest TA. In your shell scripts, you may only use the following: You may use auxiliary sed script files, etc. Make sure that they get included in the shar file. You may not write any C programs to help yourself out, nor are you allowed to use any other Unix programs (like awk or perl) in your scripts.

    Finally, your program should handle errors gracefully. For example, if the command line arguments are supposed to be files, and the user specifies a non-file, you should print a descriptive error message on standard error, and either exit or not exit as you see fit.

    1. reverse: This takes lines of text on standard input and prints them out in reverse order.

    2. nswitch takes a list of names in the form
      last name, first name 
      
      on standard input, and prints them out as
      first name last name
      
      on standard input. You can use the example_name_file as an example input file.

    3. unhtml takes a file on standard input and strips out all the html tags (anything inside < and > ). You may assume that all html tags begin and end on one line, and you don't have to deal with < and > characters that are not part of html tags.

    4. mail_strip: This takes a mail file on standard input or a mail file on the command line. The format of mail files is pretty simple. Each message contains a header and a body. The header is denoted by a line of the form
      From email_address other-stuff
      
      and ends with a blank line. Following the header is the body, which can contain any text except a line beginning with the word ``From''. The header of the next message follows the body of the previous message.

      mail_strip takes each mail message and puts it into a separate file. The file name for each message should be the email address of the sender. If there are multiple messages from the same sender (or if the file with the sender's name already exists), then append the message to that file. mail_strip should not destroy the original mail file.

      mail_strip should detect if a file is not a mail file.

      The version of mail_strip in my example programs directory is a C program. This is because there would be problems with me creating files in your directory if I used the same trick as I usually do. The result is that my mail_strip works blazingly fast. Yours can be much, much slower.

      You can find an example mail file in example_mail_file. When you run it, it should not make files called bigbill@ovaloffice.gov or mjordan@bulls.com.

      This was the only program where I used ed in the shell script.

    5. Suppose you are running a pool over the internet. People email you entries. The entries are simply supposed to be a list of teams, one per line. The teams are: Washington, Philadelphia, New York, New Jersey, Boston, Atlanta, Cleveland, Indiana, Milwaukee and Charlotte.

      Even though you instruct the participants to email you the list in that format, people always do irritating things, like list multiple teams per line (separated by a comma), abbreviate teams, put numbers before or after the team to denote where they should go on the list, etc.

      Your job is to write the shell script fixit, which takes an email file on standard input, and produces the correct format (just a list of 10 teams, spelled correctly) on standard output. There are 10 sample email entries in the files entry1 through entry7. Your program should fix them all!


    Working Examples

    Working examples are in the directory /home/cs494/labs/Sed/programs. You can run these (except for mail_strip, which you can run anywhere) only on kenner.