Assignment F

General instructions for all assignments

Provide an answer for each item in each session.
Number each answer with the same number as the corresponding item in the session assignment.
When the answer to the item is a Unix command, show the command and the system's response.
When the system prints more than 5 lines, abbreviate the response to 5 lines (unless more lines are specifically requested), showing the most important parts.
Use vi to create a file for each session, for example, create a file named sessionF1

In this assignment, show the entire file contents, even if it is somewhat longer than five lines.

Session F1

  1. Log into the system.
  2. Use the cat command to create a file containing the following data. Call it   AFS1F1   Use tabs to separate the fields.
    1425           Juan            14.25
    4321           George          21.11
    6781           Anna            16.77
    1451           Ben             21.77
    2277           Tuan            37.77
          
  3. Use the cat command to display the file and check for accuracy. Use the vi command to correct any errors in the file.
  4. Use the sort command to sort the file   AFS1F1   according to the first field. Call the sorted file   AFS1F1   (same name).
  5. Print the file   AFS1F1   (Always remember that print in UNIX means print to the screen.)
  6. Use the cut and paste commands to swap fields 2 and 3 of   AFS1F1   Call the resulting file   AFS1F1   (same name).
  7. Print the file   AFS1F1  
  8. You may log out, or continue with the following session.

Session F2

  1. Log into the system or change to your home directory.
  2. Use the tail command (you can do it, think about it) to create and save the following file. Call it   AFS2F1  
    cat   PASSES ALL DATA FROM INPUT TO OUTPUT
    cut   PASSES ONLY SPECIFIED COLUMNS
    head  PASSES NUMBER OF SPECIFIED LINES AT BEGINNING
    paste COMBINES COLUMNS
    sort  ARRANGES DATA IN SEQUENCE
    tail  PASSES NUMBER OF SPECIFIED LINES AT THE END OF DATA
    tr    TRANSLATES ONE OR MORE CHARACTERS
    uniq  DELETES DUPLICATE LINES
    wc    COUNTS CHARACTERS, WORDS, OR LINES
          
  3. Use the cat command to view the file   AFS2F1   and use vi to correct any errors.
  4. Make a backup copy of this file, so you can start over if necessary.
  5. Encrypt this file using the following steps:
    1. Reverse the file line by line (the last line becomes the first, the next to the last line becomes the second, and so on).
    2. Call the file   AFS2F1Encr  
  6. Use the cat command to view its contents.
  7. Decrypt the file (reverse the encryption steps). Call it   AFS2F1   (the original name).
  8. Use the cat command to verify that its contents are decrypted back to the original text.
  9. You may log out, or continue with the following session.

Session F3

  1. Log into the system or change to your home directory.
  2. Use the cat command to create and save the following file. Call it   AFS3F1  
    ALPHABETICAL FACTS.
    THE FIRST THREE LETTERS ARE ABC.
    THE LAST THREE LETTERS ARE XYZ.
    THE FIRST GREEK LETTER IS ALPHA.
    THE LAST GREEK LETTER IS OMEGA.
          
  3. Use the cat command to view the file   AFS3F1   and use vi to correct any errors.
  4. Make a backup copy of this file, so you can start over if necessary.
  5. Use the translate command to encrypt this file by shifting each letter five characters toward the end of the alphabet. Call the encrypted file   AFS3F1Encr  
  6. Use the cat command to view its contents.
  7. Now use decryption (reverse strategy) to decrypt the file. Call the new file   AFS3F1   (the original name).
  8. Use the cat command to verify that its contents have been decrypted back to the original text.
  9. You may log out, or continue with the following session.

Session F4

  1. Log into the system or change to your home directory.
  2. Use the cat command to create and save the following file. Call it   AFS4F1   (Do not type the headings).
    ID          Hourly Rate     Hours Worked
    
    1420         12.56          45
    3456         14.56          22
    2341         45.12          34
    1122         23.56          28
    1443         23.23          19
    2351         67.90           9
    8001          7.00          14
          
  3. Use the cat command to view the file   AFS4F1   and use vi to correct any errors.
  4. Use a command to show the number of workers.
  5. Use one single command line to show the worker who is paid the highest hourly rate.
  6. Use one single command line to show only the ID of a worker who worked the most hours.
  7. You may log out, or continue with the following session.

Session F5

  1. Log into the system or change to your home directory.
  2. Use the cat command to copy the file   AFS4F1   and name the copy   AFS5F1  
  3. Use the cat command to create and save the following file. Call it   AFS5F2   (Do not type the headings).
    ID          Hourly Rate     Hours Worked
    
    1420         12.58          21
    2456         14.58          23
    2341         45.14          32
    1322         23.58          18
    1443         23.25          17
    2351         67.92          36
    3467         56.92          24
          
  4. Use the cat command to view the file   AFS5F2   and use vi to correct any errors.
  5. Sort   AFS5F1   by ID and call the resulting file   AFS5F1Sorted  
  6. Print the resulting file.
  7. Sort   AFS5F2   by ID and call the resulting file   AFS5F2Sorted  
  8. Print the resulting file.
  9. Merge files   AFS5F1   and   AFS5F2   into a new file called   AFS5F3   which is ordered on the ID field.
  10. Print the resulting file.
  11. Use a sort command to remove one of the lines when two lines have the same ID. Save the resulting file as   AFS5F3   (the same name).
  12. Print the resulting file.
  13. You may log out, or continue with the following session.

Session F6

  1. Log into the system or change to your home directory.
  2. Use the cat command to create and save the following file. Call it   AFS6F1   (Do not type the headings).
    Session	  Course  Department   Enrollment
    
    1	  15	  CIS          45
    1	  54	  CIS          20
    2	  34	  BUS          20
    2	  11	  ENG          89
    1	   5	  CIS          38
    1	  35	  MTH          56
    2	  35	  MTH          41
    2	  17	  PE           25
    2	  54	  CIS          67
          
  3. Use the cat command to view the file   AFS6F1   and use vi to correct any errors.
  4. Use a single command to print the file   AFS6F1   sorted as follows:
  5. You may log out, or continue with the following session.

Session F7

  1. Log into the system or change to your home directory.
  2. Make a copy of /etc/passwd file and save it in a file called   AFS7F1  
  3. Use a command to count the number of users in this file.
  4. Cut the file so that each line has only two columns: login name (column 1) and user id (column 3). Call the new file   AFS7F2  
  5. Sort the file   AFS7F2   on login name. Save the file as   AFS7F2   (same name).
  6. Print the last five lines in the file.
  7. Log out of the system.

Submission session

Create a heading similar to the heading for assignment A.

Tommy Atkins   replace with your name
CIS 18A    
Winter 2011   replace with the current quarter
AssignmentF   replace with the current assignment letter

  1. Use the following command to create a file with your work from the assignment:
    cat headingF sessionF1 sessionF2 sessionF3 sessionF4 sessionF5 sessionF6 sessionF7 > assignmentF.txt
  2. Use e-mail or WinSCP to obtain a copy of assignmentA.txt. Print it using notepad, or otherwise use the Courier New or other mono-space font.
  3. Turn in your printout to the instructor on time.