首页
学习
活动
专区
圈层
工具
发布

Linux练习
EN

Stack Overflow用户
提问于 2022-11-21 01:35:47
回答 1查看 48关注 0票数 -5

我有这个练习,我解决不了。

用空字符串替换所有的para>和标记。如果结果行为空,则删除该行。(您可能需要使用花括号来实现这一点。)

这是我获得的文档(web.docbook)的一部分:

代码语言:javascript
复制
<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 &lt; and &gt; mark off elements.
</para>

<listing>
&lt;body&gt;
&lt;div id="top-navig"&gt;
&lt;a id="top"&gt;&lt;/a&gt;
&lt;a href="index.html"&gt;CIT 040 Index&lt;/a&gt;
&amp;gt;
Assignment 1
&lt;/div&gt;

我能够解决第一部分的练习,这是完美的,但我不知道如何只删除那些空行,这是我的替代结果。

如果你能帮我,我会非常感激的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-21 02:15:00

不确定你是否真的是,假设使用一些条件词和花括号,但这很好;)并对文本做你想要的.

代码语言:javascript
复制
$ sed -E '/^<\/?para>$/d;s/<\/?para>//g' web.docbook
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.

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.

Web pages are written in a markup language called HTML. Here is what it
looks like. The &lt; and &gt; mark off elements.

<listing>
&lt;body&gt;
&lt;div id="top-navig"&gt;
&lt;a id="top"&gt;&lt;/a&gt;
&lt;a href="index.html"&gt;CIT 040 Index&lt;/a&gt;
&amp;gt;
Assignment 1
&lt;/div&gt;
$
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74513357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档