Sonoma State University
Department of Computer Science
CS-210: Introduction to Unix
Exercise 8: File Processing (part 2)

Objective:

In this exercise, you will learn how to use some basic commands to concatenate, compare, search, sort, and count the contents of a text file.

Instructions:

Inside your home directory, please perform the following tasks:

  • cd cs210_exercises/cs210_exercise_8
  • wget https://www.robertjamesbruce.com/programming_exercises/cs210/fall_2024/cs210_exercise_8.tgz
  • tar xzf cs210_exercise_8.tgz

Question 1: comparing files

  • Using the diff command, Compare the original file, "Chapter_3-The_Wonderful_Wizard_of_Oz.txt" with "MODIFIED-Chapter_3-The_Wonderful_Wizard_of_Oz.txt".
  • Which word(s) were changed in Chapter 3 of the Wonderful Wizard of Oz?

Question 2: file compression effectiveness

  • Note: Before issuing a zip, gzip, or bzip2 command (below), be sure to make copies of "The_Wonderful_Wizard_of_Oz.txt" because these compression commands will remove the original file.
  • Using the zip commmand, compress the following file, "The_Wonderful_Wizard_of_Oz.txt" (the compressed file will be named "The_Wonderful_Wizard_of_Oz.txt.zip"
  • Using the gzip commmand, compress the following file, "The_Wonderful_Wizard_of_Oz.txt" (the compressed file will be named "The_Wonderful_Wizard_of_Oz.txt.gz"
  • Using the bzip2 commmand, compress the following file, "The_Wonderful_Wizard_of_Oz.txt" (the compressed file will be named "The_Wonderful_Wizard_of_Oz.txt.bz2"
  • Comparing the file sizes of "The_Wonderful_Wizard_of_Oz.txt.zip", "The_Wonderful_Wizard_of_Oz.txt.gz" and "The_Wonderful_Wizard_of_Oz.txt.bz2", which compressed file is the smallest in size? What is the difference (in bytes) between the largest file size and the smallest file size?
  • Comparing the most compressed file (i.e. the smallest in size) with the uncompressed text of "The_Wonderful_Wizard_of_Oz.txt" how many bytes were saved during compression?

Question 3: globally substituting a string for a character with sed

  • Note: The input file, "The_Wonderful_Wizard_of_Oz.txt" contains "\r" (carriage return) and "\n" (line feed) at the end of each line.
  • Using cat, a pipe, sed, and redirection to an output file, "CR-The_Wonderful_Wizard_of_Oz.txt", replace all occurrances of the "\r" (carriage return) with "<CR>" in the input file, "The_Wonderful_Wizard_of_Oz.txt".
  • What is the exact Unix command you entered on Blue to answer question 3?

Question 4: Decoding a secret file with tr

  • The following file has been obfuscated by a simple form of encryption: "secret.txt".
  • Only uppercase letters "A" through "Z" are encoded. All other characters should remain unchanged.
  • Using the tr command, what is the unencrypted message?
  • What is the exact tr command you entered on Blue to decode this messsage?
  • The procedure to decrypt the file is as follows:
    INPUT LETTER OUTPUT LETTER
    R A
    L B
    X C
    K D
    D E
    J F
    Q G
    V H
    C I
    T J
    S K
    Z L
    N M
    E N
    I O
    M P
    A Q
    B R
    H S
    O T
    G U
    F V
    P W
    Y X
    U Y
    W Z

Submission Instructions:

Please submit your answers to Canvas for the questions above.

Exercise 8 Rubric

CRITERIA RATINGS POINTS
Question 1: Comparing files Proficient
0.25 points

Comparing the original file, "Chapter_3-The_Wonderful_Wizard_of_Oz.txt" with "MODIFIED-Chapter_3-The_Wonderful_Wizard_of_Oz.txt", student noted which word(s) were changed in Chapter 3 of the Wonderful Wizard of Oz.
Below Expectation
0 points

Student provided no answer to the question.
0.25 points
Question 2: file compression effectiveness Proficient
0.25 points

Student noted which of the three compression programs (zip versus gzip versus bzip2) created the smallest file. Student noted the difference in bytes between the largest compressed file size and the smallest compressed file size. Student noted the difference between the uncompressed text of "The_Wonderful_Wizard_of_Oz.txt" and the most compressed file (i.e. the smallest in size).
Satisfactory
0.18 points

Student answered two of the three questions: 1. Which of the three compression programs (zip versus gzip versus bzip2) created the smallest file? 2. What is the difference in bytes between the largest compressed file size and the smallest compressed file size? 3. What is the difference between the uncompressed text of "The_Wonderful_Wizard_of_Oz.txt" and the most compressed file (i.e. the smallest in size).
Below Expectation
0 points

Student provided no answer to the question.
0.25 points
Question 3: globally substituting a string for a character with sed Proficient
0.75 points

Using cat, a pipe, sed, and redirection to the output file, "CR-The_Wonderful_Wizard_of_Oz.txt", student submitted a valid Unix command that, if entered on Blue, would replace all occurrences of the "\r" (carriage return) replaced with the literal text "" for the input file "The_Wonderful_Wizard_of_Oz.txt".
Satisfactory
0.53 points

Student submitted a Unix command. If entered as-is on Blue, this command would NOT replace all occurrences of the "\r" (carriage return) replaced with the literal text "" for the input file "The_Wonderful_Wizard_of_Oz.txt". The student's Unix command may fail because of syntax error(s) OR logic errors in the command itself.
Below Expectation
0 points

Student provided no answer to the question.
0.75 points
Question 4: Decoding a secret file with tr Proficient
0.75 points

Student submitted a tr command that, if entered on Blue, is syntactically correct and properly translates the input text (secret message) into a comprehensible, decoded message.
Satisfactory
0.53 points

Student decoded the secret message. If the student submitted a tr command, the command would be unable to decode the secret message if entered on Blue.
Below Expectation
0 points

Student provided no answer to the question.
0.75 points
Total points: 2