sed Exercise
Do the exercise on pages 155-156 of your book. Put numbers 1-9 into a
file named
lastname_firstname_sed.sh.
The file for number 10 should be
placed into a file named lastname_firstname_edit.sed.
Here is the datebook
file for this exercise.
Note: Don't use sed’s a command to append
the asterisks at the end of the line in step 6. The a command
adds new lines. You want the asterisks to be at the end of the line, not
on a new line.
Also, do the following task, and put it in a file named
lastname_firstname_docbook.sed
The input file will be a file written in Docbook format, which is a format designed for writing books and documentation. It looks a little bit like HTML, the language that is used for Web pages.
Docbook files consist of text with markup, or “tags” that
tell how the text is to be displayed. An opening tag is a command enclosed in
angle brackets < and >. For example, <para> means “start a
paragraph”. The corresponding closing tag that means “end a
paragraph” is written </para> (note the slash after the less
than sign).
Here is the document that you will be modifying; just copy and paste it into a text file on your system.
<article> <title>About the Web</title> <para> This is an article about the World Wide Web. The World Wide Web is a collection of documents that are linked to one another. The Web is <emphasis>not</emphasis> the same as the Internet. The Internet is a world-wide network of networks, and it does far more than simply serve up Web pages. </para> <para>Tim Berners-Lee, the inventor of the World Wide Web, put special emphasis on the portability of web pages. Rather than create a proprietary format, he made Web pages dependent only upon plain ASCII text.</para> <para> Web pages are written in a markup language called HTML. Here is what it looks like. The < and > mark off elements. </para> <listing> <body> <div id="top-navig"> <a id="top"></a> <a href="index.html">CIT 040 Index</a> &gt; Assignment 1 </div> <h1>Assignment 1</h1> <p>This exercise shows you how to use the two computer environments that you will use in this class. You will:</p> <ol class="upper-roman"> <li>Set up your directories on Windows. This is where you will write your HTML documents.</li> </ol> </listing> <para>It looks difficult, but it is possible to learn HTML in a few weeks. <emphasis>You, too can create web pages for viewing by friends and family!</emphasis> Note that, in our listing, we had to encode > as &gt. </para> </article>
Write a sed file that does the following. It should work on any Docbook file, not just this one. That means you can’t count on a particular tag always being on a particular line.
<article> and
</article> should be deleted.<title> with Title:, and
replace </title> with nothing.<para> and </para>
tags with the null string. If the resulting line is empty, delete the line.
(You may need to use curly braces to make this happen.)<emphasis> and
</emphasis> tags with asterisks. Thus:
will becomeThis is a <emphasis>great</emphasis> bargain.
This is a *great* bargain.
web with Web everywhere.<listing> by ---begin listing</listing> by
---end listing<listing> and
</listing>, do these things (you must use
curly braces to do this!):
< with <.> with >.& with &.Note: The & character is a special metacharacter when used in the “replacement” portion of a substitution. For example, if you want to replace the word “and” with “&”, you would do this:
s/and/\&/
Your resulting file will look like this.
When you finish, put all three files into a single .zip file and mail it to the instructor. Please make sure that you put CIT052 in the subject line of your email.