Objectives
In this lab you will use the vi editor to create
new files and edit existing files.
Forum
If you get stuck, have a question or want to share something you learned with this lab then use the CIS 90 Forum at
http://simms-teach.com/forum/viewforum.php?f=9
Procedure
Log on to a Unix machine so that you have a command line shell at your
service. Change directory to edits to start this lab.
-
Create a text file called home using vi and insert
the following lines:
cd
clear
echo This is the home directory of $LOGNAME
echo =======================================
ls -F
-
Use the chmod command to set the permissions on the file,
home
to -rwxr-xr-x.
-
Enter the command home and see what happens. Is it what
you would expect?
-
Move this shell script you have just made to your bin directory,
so that you may run it from anywhere on the system.
Congratulations: you have just written your first shell script!
-
Run the spell command on the file small_town:
spell small_town
Note all the misspelled words.
-
Make a permanent list of the above misspelled words by running the spell
command again, but this time, redirect the output to a file called, words.
-
Use vi to edit the small_town file and:
- correct all the misspelled words.
- move the "Reprinted from ..." line to the bottom
- get rid of duplicate lines and extraneous characters in the file.
- use a consistent indentation.
- fix the misspelling on the line.
"The biggest business ..." line where the misspelled word is spelled correctly!
(change on to in)
TIPS:
- use the dd command to delete lines.
- use yy and p commands to copy and paste.
- use /string command to search for misspelled words.
- use x command to delete single characters.
- use i command to do normal notepad-like screen editing, and Esc to get back to command mode.
- use two login Putty sessions, one to edit small_town, the other for words.
-
When you have fixed all the spelling errors, run the spell command again.
What should be done with words like "Ayshire", "moshpit" or "mashpit"
that aren't in UNIX's dictionary?
-
Edit the file words and remove all the misspelled words that you
have corrected. (Only Ayshire and moshpit should remain in the file.)
-
Enter the following three commands from your shell prompt:
$ date
$ echo Now is the time for all good men to come to the aid of their party
$ cal
Use command line editing to redisplay the echo command, and change the
word
men to women. Then re-execute the command. Hint: to enter
command line editing mode, press the up-arrow key.
-
Re-execute the command once more, but this time redirect the output to
a file called women. You should now have a file named women with a single
line in it.
-
Here is a little project for you to accomplish on a UNIX system:
-
I have emailed a message titled, "Technology for Mountain Folk" to your Opus account.
Read your mail and save this message to a file called,
vocab
in your edits directory.
-
vi the vocab file and remove the numbers and spacing
in front of each definition. Also remove the extraneous mail headers.
-
Sort this list so that it is in Dictionary order and save the results in
a temporary file.
-
Rename the above temporary file to vocab. Now your vocabulary list
is in alphabetic order. Make any necessary adjustments to the file, e.g. making
sure the title is at the top of the page and that there are no broken sentences.
-
To get credit for this lab, you must send me the following five files that
you have created or edited in this lab. I want these files bundled up into
a single text file called lab09.$LOGNAME (where $LOGNAME is your login name) and deposited in the directory:
/home/rsimms/cis90/
The five files are:
home
words
small_town
women
vocab
One command that might do this could be (all on one line):
cat home words small_town women vocab > /home/rsimms/cis90/lab09.$LOGNAME