#11 - The sed Utility
This lab is considered optional. If you perform this lab and submit it to your instructor, you will get a BONUS lab mark.
View the lab submission instructions at the end of this lab...
***This Lab is to be done individually.***
- Log in to your matrix account or any
available bash shell.
- In your home directory, create a subdirectory
- Make Lab11 your working
directory and remain there for the rest of this Lab. Place a copy of /etc/passwd
in your current directory.
- Please note that, rather than using a
pattern in sed (/pattern/), you can also state a line number or a range
of line numbers. Also remember that sed's
default behavior is to print all lines, not just matching ones. With
that in mind, using sed or any
other command necessary:
- Display lines 5
through 15 of passwd.
- Display the last 3
lines of group.
- Display the last line
How many ways can this be done with and without sed?
- Try the
following (in your Lab11
s/false/$(tput smso)FAKE$(tput rmso)/g passwd
- Now try
quoting the substitution pattern (single quotes) like you normally
- What did
the first one do (#5)? (Look up tput)
- Why did
the second one (#6) do what it did?
- If ^ means
beginning of line and $ means end of line, how could you remove blank
lines from a file? Test it using one of your shell scripts.
- Print all
lines from passwd
EXCEPT lines 1 through 20.
11. Write the
result of #5 to a file named fake.pass
12. Append the comment "# this is not a real shell" below
all instances of the "FAKE" shell in fake.pass
and write it to STDOUT.
13. Insert the comment "# Oh mighty root. I am not worthy!"
above root's record in fake.pass
14. Using vi, create
a file called lab11.ans and copy in there the answers to questions
4, 7-11, and 13.
Precede each answer with the number of the
question followed by a period, e. g. 4. Your Answer to question #4.
Submit your Lab #11:
1. Make certain that you are currently located in the lab11 directory
2. Issue the following Bash Shell script to check and if correct, send e-mail to your OPS435 professor (works only for Murray Saul's sections):
This shell script should either indicate problems and hints for you to correct your shell script, or indicate that your lab #11 submission was successful. If your lab was successfully submitted, both you and your OPS435 professor (Murray Saul) should have received an e-mail message.
Note: Keep this e-mail message for the remainder of the semester as date and time stamp proof that you submitted the lab in case there is a discrepancy with your OPS435 lab grade...