如何使用在每个段落{p}
前后添加带有段落标签的纯文本{/p}
段落sed
?每个段落用空白行分隔。我可以使用它sed -e 's/^\s*$/<r>/ somefile.txt
来查找文本文件中的每个空白行,但这总是会在所有位置插入{p},我不太了解如何更改它们。此外,最后一段之后没有空行,因此最后一段不会做任何事情。
输入文本:
Section 5. General Information About Project Gutenberg-tm electronic
works.
Description
Professor Michael S. Hart is the originator of the Project Gutenberg-tm
concept of a library of electronic works that could be freely shared
with anyone.
Project Gutenberg-tm eBooks are often created from several printed
editions, all of which are confirmed as Public Domain in the U.S. unless
a copyright notice is included.
要求的输出:
Section 5. General Information About Project Gutenberg-tm electronic
works.
{p}
Description
{/p}
{p}
Professor Michael S. Hart is the originator of the Project Gutenberg-tm
concept of a library of electronic works that could be freely shared
with anyone.
{/p}
{p}
Project Gutenberg-tm eBooks are often created from several printed
editions, all of which are confirmed as Public Domain in the U.S. unless
a copyright notice is included.
{/p}
当您最初要求sed
解决方案时,我附上一个:
sed '/./{H;1h;$! d}
g;/{p}$/d
s#^{p}.*#&\n{/p}#;p
s/.*/{p}/;h;d' somefile.txt
解释
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句