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
- Log into the system.
- 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
- Use the cat command to display the file and check for accuracy.
Use the vi command to correct any errors in the file.
- Use the sort command to sort the file AFS1F1
according to the first field.
Call the sorted file AFS1F1 (same name).
- Print the file AFS1F1
(Always remember that print in UNIX means print to the screen.)
- Use the cut and paste commands to swap fields 2 and 3 of AFS1F1
Call the resulting file AFS1F1 (same name).
- Print the file AFS1F1
- You may log out, or continue with the following session.
Session F2
- Log into the system or change to your home directory.
- 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
- Use the cat command to view the file AFS2F1  
and use vi to correct any errors.
- Make a backup copy of this file, so you can start over if necessary.
- Encrypt this file using the following steps:
- Reverse the file line by line (the last line becomes the first, the
next to the last line becomes the second, and so on).
- Call the file AFS2F1Encr
- Use the cat command to view its contents.
- Decrypt the file (reverse the encryption steps).
Call it AFS2F1 (the original name).
- Use the cat command to verify that its contents are decrypted back to the original text.
- You may log out, or continue with the following session.
Session F3
- Log into the system or change to your home directory.
- 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.
- Use the cat command to view the file AFS3F1
and use vi to correct any errors.
- Make a backup copy of this file, so you can start over if necessary.
- Use the translate command to encrypt this file by shifting each letter five
characters toward the end of the alphabet.
- For example, A becomes F, B becomes G, and so on.
- The end of the alphabet will wrap around. For example, Y becomes D and Z becomes E.
- Spaces and newlines are preserved.
- This is called Caesarian encryption because the first known user was Julius Caesar.
Call the encrypted file AFS3F1Encr
- Use the cat command to view its contents.
- Now use decryption (reverse strategy) to decrypt the file.
Call the new file AFS3F1 (the original name).
- Use the cat command to verify that its contents have been decrypted back to the original text.
- You may log out, or continue with the following session.
Session F4
- Log into the system or change to your home directory.
- 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
- Use the cat command to view the file AFS4F1
and use vi to correct any errors.
- Use a command to show the number of workers.
- Use one single command line to show the worker who is paid the highest hourly rate.
- Use one single command line to show only the ID of a worker who worked the most hours.
- You may log out, or continue with the following session.
Session F5
- Log into the system or change to your home directory.
- Use the cat command to copy the file AFS4F1
and name the copy AFS5F1
- 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
- Use the cat command to view the file AFS5F2
and use vi to correct any errors.
- Sort AFS5F1 by ID and call the resulting file
AFS5F1Sorted
- Print the resulting file.
- Sort AFS5F2 by ID and call the resulting file
AFS5F2Sorted
- Print the resulting file.
- Merge files AFS5F1
and AFS5F2
into a new file called AFS5F3
which is ordered on the ID field.
- Print the resulting file.
- 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).
- Print the resulting file.
- You may log out, or continue with the following session.
Session F6
- Log into the system or change to your home directory.
- 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
- Use the cat command to view the file AFS6F1
and use vi to correct any errors.
- Use a single command to print the file AFS6F1
sorted as follows:
- Sort using Department as the primary key.
- In case of identical Departments, sort using Course as the secondary key.
- In case of identical Departments and Courses, sort using Session as the ternary key.
- You may log out, or continue with the following session.
Session F7
- Log into the system or change to your home directory.
- Make a copy of /etc/passwd file and save it in a file called
AFS7F1
- Use a command to count the number of users in this file.
- 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
- Sort the file AFS7F2 on login name. Save the file as
AFS7F2 (same name).
- Print the last five lines in the file.
- 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
- 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
-
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.
- Turn in your printout to the instructor on time.