Editing Files With vi (Extra Credit)#
In this lab you will use the vi editor to create new files and edit existing files.
Procedure#
Log on to opus so that you have a command line shell at your service. Change directory to edits to start this lab.
Create a text file called
homeusingviand insert the following lines:cd clear echo This is the home directory of $LOGNAME echo ======================================= ls -F
Use the
chmodcommand to set the permissions on the file, home torwxr-xr-x.Enter the command
homeand see what happens. Is it what you would expect?Move this shell script you have just made to your
bindirectory, 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_townNote all the misspelled words.
Make a permanent list of the above misspelled words by running the
spellcommand again, but this time, redirect the output to a file calledwords.Use vi to edit the
small_townfile and:correct all the misspelled words.
move the “Reprinted from …” line to the bottom.
get rid of duplicate lines, repeated words and extraneous characters in the file.
use a consistent indentation.
fix the typo on the line: “The biggest business on town …” (change to in)
fix the typo on the line: “The airport runaway…” (change to runway)
Tips:use the
ddcommand to delete lines.use
yyandpcommands to copy and paste.use
/stringcommand to search for misspelled words.use
xcommand to delete single characters.use
icommand to do normal notepad-like screen editing, andEscto get back to command mode.use two login terminal sessions, one to edit
small_town, the other forwords.
When you have fixed all the spelling errors, run the
spellcommand again.Edit the file
wordsand 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
echocommand, 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 namedwomenwith a single line in it.
Submittal#
To get credit for this lab, you must send me all the files that you have created or edited in this lab.
Bundle (concatenate) the files below into a single text file in your home directory named
editing.txt:homewordssmall_townwomen
Copy your
editing.txtfile to the/home/mmatera/turnindirectory renaming it asediting.txt.$LOGNAME. This can be done in a single command.
You can submit as many times as you like up to the deadline.